aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Jtable not showing updates after setValueAt() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable not showing updates after setValueAt()" Watch "Jtable not showing updates after setValueAt()" New topic
Author

Jtable not showing updates after setValueAt()

Lance Mead
Greenhorn

Joined: Oct 22, 2012
Posts: 3
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

Joined: Jun 19, 2010
Posts: 825
    
    5

Can we see some code?


The quieter you are, the more you are able to hear.
Lance Mead
Greenhorn

Joined: Oct 22, 2012
Posts: 3
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

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

Joined: Oct 22, 2012
Posts: 3
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

Joined: May 03, 2008
Posts: 4522
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable not showing updates after setValueAt()
 
Similar Threads
JTable Problem...
JTable(!!!)
jtable
Checkbox editor for JTable column
Refresh JTable