• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating JTable

 
Preeti Yarla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a JTable with custom table model. My table model extends AbstractTableModel and its data is in a ResultSet obtained after executing a query on database.

I am able to populate this JTable with records from the database. The next step I wanted is to insert records into JTable and so I provided the required GUI components.But the record I added does not get updated in the JTable until I restart my application.

What do I need to do in order to refresh the JTable immediately without having to restart the application?

Do I need to implement any listener? I used fireDataChanged() on tablemodel but its not working.
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Preeti Yarla:
I created a JTable with custom table model. My table model extends AbstractTableModel and its data is in a ResultSet obtained after executing a query on database.

I am able to populate this JTable with records from the database. The next step I wanted is to insert records into JTable and so I provided the required GUI components.But the record I added does not get updated in the JTable until I restart my application.

What do I need to do in order to refresh the JTable immediately without having to restart the application?

Do I need to implement any listener? I used fireDataChanged() on tablemodel but its not working.


Sounds like you are not refreshing your model properly. Execute the query again and provide the model a new ResultSet, then call fireTableDataChanged().
 
Preeti Yarla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Execute the query again and provide the model a new ResultSet


I did that part and then fireTableDataChanged() and a revalidate() and a repaint() on the table. And I also verified that the resultset in my table model is actually changing. But the table on the GUI itself is not refreshed. What else may be going wrong?
[ June 04, 2008: Message edited by: Preeti Yarla ]
 
Preeti Yarla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ! its actually working now. I have been using different objects of my table model at different points. like

table.setModel(new MyTableModel());

new MyTableModel().insertRecord();

The tablemodel object that table is using is not getting updated after an insert. No wonder the table is not refreshed. With everything working now all that looks like silly mistakes.
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic