• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable updation problem

 
Krithika Beri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All these stuffs are redundant:


Simply call the method fireTableDataChanged() at the end:


jTable1.setModel(tableModel);
tableModel.fireTableDataChanged();
 
Krithika Beri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that. It did not help
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic