Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Define a header of a JTable and set a value into it  RSS feed

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want to create a JTable which "Analysis","Date" and "Price" the names of columns in header. Here's a piece of my code :



So, the value of Analysis and Price were stored in my Data Base, and the Date get the value of the current day.
How can i create this JTable and how can i set the value into it ?
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How familiar are you with Tables already?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "object[][]data " in JTable is dynamic .
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarra Sakka wrote:The "object[][]data " in JTable is dynamic .

Arrays are not dynamic. However you can have the data as a List instead
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a class MyModel the followings :

And i create a Bean MyElement the following :

this is a piece of my code which this class :


Am I on the right path?? if yes, what should i do after that ?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a result i obtain a Table with 3 coloumn "A","B" and "C".I don't know hence these name comes!!!
Should you please to know how can i put my columns names "Analyse", "Date d'analyse","Prix" as a header in my Table?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done. You are on the right track.
1) Why did you extend abstract table model? Try extending Default table model.
2) Override the getColumnName() to return the name you desire (from your columnNames)
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean like this :
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very well, the column names appears now
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem now, when i add a new element the previous element will be overwritten
Would you please tell me where's the problem in my code :
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quit cross posting: http://stackoverflow.com/questions/28275181/set-value-in-jtable-dynamically

We don't appreciated spending time to answer questions only to find out they have already been answered in another forum.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for this behavior, i need a solution that's why :/
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just BeForthrightWhenCrosspostingToOtherSites (<- click) next time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!