• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Refreshing JTable

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JTable that is not editable. It gets its data from an xml file. I want to make sure that each time the file is changed, the changes are reflected in the table view. How do I update the table? repaint() does not work.
Thanks
-Deb
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Debbie,
You only need to update the "TableModel" associated with the "JTable".
The "javax.swing.table.TableModel" is an interface. If you are not specifically associating a "TableModel" with your "JTable", then your "TableModel" will be implemented by a class that extends "javax.swing.table.AbstractTableModel" (which is usually "javax.swing.table.DefaultTableModel").
If this is the case, then, whenever you modify the data in the "AbstractTableModel", it will notify the "JTable" that the data has been modified, and the "JTable" should refresh itself.
I suggest you refer to the javadocs for "JTable", "AbstractTableModel", "DefaultTableModel" and "TableModel" for more details.
The "tables" chapter from the book "Swing" (by Matthew Robinson and Pavel Vorobiev) is available for download from here:
http://developer.java.sun.com/developer/Books/swing2/
And there is also the "How to Use Tables" lesson in the "Java Tutorial":
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
Hope this helps you.
Good Luck,
Avi.
 
Debbie Argulkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Avi,
Thanks a lot for your prompt and helpful reply. I am going through those chapters now and will hopefully solve the problem.
Thanks
-Deb
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I remember correctly, you need to call firTableModelChane() method in order for JTable to repaint.
 
Debbie Argulkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I just modified the data in the DefaultTableModel and it worked!!!
Thanks,
-Deb
 
You can't expect to wield supreme executive power just because
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic