aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable updation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable updation problem" Watch "JTable updation problem" New topic
Author

JTable updation problem

Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
I am using Netbeans for my current project. I require to update a jtable based on what the user selects from a JTree consisting of all the files in his computer. The problem is that this JTable is not getting updated.
I am creating a new model and adding it each time. When I say getValueAt(x,Y) from the new value, it is giving me proper updation but this is not visible in UI. Please help



Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

All these stuffs are redundant:


Simply call the method fireTableDataChanged() at the end:


jTable1.setModel(tableModel);
tableModel.fireTableDataChanged();


PM Me If You Want to get Urgent Help on Java Programming
Krithika Beri
Ranch Hand

Joined: Sep 11, 2012
Posts: 36
I tried that. It did not help
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4659
    
    5

The only method needed is JTable#setModel(...). You do not need to call fireTableDataChanged(). If you're not seeing the new model's data in the table, chances are you're setting the model to the wrong table.

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.


luck, db
There are no new questions, but there may be new answers.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
- agreed with Darryls request for SSCCE, otherwise everything here could be shots to the dark, including my post here

- never to call simple useless

a) jTable1.fireTableDataChanged() for DefaultTableModel, this and all notifiers are implemented correctly

b) jTable1.validate(); do nothing in your case

c) jTable1.repaint(); do nothing in your case, even for doLayout(special casses for determine of setPreferrdSize) could eb usefull

d) jTable1.updateUI(); do nothig in your case, because you dont created CustomUI for JTable

- depends of case if

a) selection from JTree add a new row to JTable, then to add a new row to the DefaultTableModel

b) selection update some of row(s), then to JTable#setValueAt(valid for DefaultTableModel)
 
jQuery in Action, 2nd edition
 
subject: JTable updation problem