• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing data in a JTable

 
Flavio Nobili
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all,
Since I need to change the data in a JTable I've been using the following:

Is it right? Do you know another way to do such thing?

Thanks,
Fl�vio.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Flavio,
Looks good, but it depends on what's in MyTableModel. Usually you start with data and header in vectors or arrays, feed that into some table model constructor, and feed the resulting table model into a JTable constructor. I'm not sure whether that line of your code is your first or your thousand's so I am not sure how you need help.
 
Flavio Nobili
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eddie,
The "records" variable is a pointer to an array, it works weel when I construct my JTable. But, when this array is changed the table is not automatically changed. I have to create another table model, giving the records as argument, and set the model of the table using setModel. This way the table data is updated. But, there must be a better way to do that. Don't you think so?

Regards,
Fl�vio.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at JTable.setValueAt()
and more importantly
How to use tables
.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!