• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable not showing updates after setValueAt()

 
Lance Mead
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am updating a JTable with table.setValueAt(obj val, row, col); but all the rows show the data from the last entry. The code copies the values from a class into the table using setValueAt(). i have tried to manually call firedata change commands with no change. The table is created with the Default Table Model and I am not doing anything different. The debugger shows the correct data at the setValueAt() call.

Any ideas?
Thanks for the help,
Lance
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we see some code?
 
Lance Mead
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to suggest that, since you have a reference to the table model, you should be calling setValueAt() on the table model. But I see (at line 47 to 59) that you have some code which modifies the contents of the table model in a radical way before you call setValueAt(). That seems kind of fishy to me.

Also, the code at lines 51 to 53 has a hidden gotcha, in that it won't actually remove all of the rows from the model (assuming the table model stores its data in an ordinary way).

Can you show us the code for your table model, or is it one of the standard Swing classes?
 
Lance Mead
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table uses the default table model settings, nothing changed. The table rows are added and deleted so there needs to be a way to re-size during run time. The table does re-size but all the rows show the data of the last row.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because you're adding the same Vector to all the rows. You need to move Vector <String[]> v = new Vector<String[]>(listSize); inside the loop that adds the rows.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic