• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

updating JTable

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear it
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic