Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refrash JTable?

 
Jack Yang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
How to reflash the JTable so after I book or cancel,it can reload the data automaticlly?
 
Rick Bos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you have a TableModel for the JTable.
You have to do two things:
1) update the data that the TableModel uses
2) getTable().repaint();
That worked for me on my assignment.
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just did this in my setValueAt() method that I overrode...

That way everything was always up to date. And that is the way I found in a Sun tutorial
 
Sarita Gupta
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a setModel to refresh the table with the new search result and it worked.
Sarita
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sarita Gupta:
I did a setModel to refresh the table with the new search result and it worked.

Unless the actual data model changed and not just the data, you're better off doing something similar to what Nate said. In the case of new search results you can call fireTableDataChanged() from your table model.
Michael Morris
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2) getTable().repaint();

If you need to call repaint() to see the data refreshed in the table, it indicates some problem in your table code. The table MV mechanism should ensure that the table is refreshed whenevr you change data. All you have to do is to change the data in the model and fire the appropriate table method.
Eugene.
 
Sarita Gupta
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Micheal:
Unless the actual data model changed and not just the data, you're better off doing something similar to what Nate said. In the case of new search results you can call fireTableDataChanged() from your table model.

Well I did as such after following an example I came across. Anyways, after reading ur reply and going thru the Java tutorial, I think I'll to make some changes in mine.... good that someone pointed it out to me else I'd be thinking that mine's the right and easy way of updating the table....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic