This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable data not refreshing on UI when changing TableModel Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JTable data not refreshing on UI when changing TableModel" Watch "JTable data not refreshing on UI when changing TableModel" New topic
Author

JTable data not refreshing on UI when changing TableModel

Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
HI Guys,

I am facing a tough time here.
I am using JTable and created my own custom pagination thing for it.
I have a file which containf thousands of records and initially i want to show on 100 or so (anything which user specifies).
for which i have created this UI Structure

A frame contains a JSplitPane, inside JSplitPane left component, i am setting a JPanel (viz. EventTablePanel), this panel contains 1 JScrollPane(say A) and 1 JPanel (say B). JScrollPane (A) vieweport has been set as JTable which have its backing TableModel. JPanel (B) has few buttons (like previous and next).
Intially the table looks fine, when i read 100 records from the file. when user clicks on "NEXT button" inside JPanel (B), i set some indexes, based on which i repopulate the TableModel of JTable with new set of records.
and after that i repaint the whole stuff like this.





Now, when i check the new scrollPane viewPort and its JTable's table model, i get the correct data (i.e, next 100 records with indexes 101 to 200), but its not getting repainted. i tried using invaildate, validate and what not.
Can someone please help me out with this. What am i doing wrong here?

Regards,
Akhil


-------------------------------<br />you can't move ahead, unless you try for it.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 852
Originally posted by Akhil Jain:
when user clicks on "NEXT button" inside JPanel (B), i set some indexes, based on which i repopulate the TableModel of JTable with new set of records.
and after that i repaint the whole stuff


You shouldn't have to repaint anything manually.

When the table model gets repopulated, make sure its fireTableDataChanged() method gets called and all should be well.

(If your TableModel implements TableModel without extending AbstractTableModel then you'll have to create an event [new TableModelEvent(yourTableModel)] and dispatch it to all listeners yourself.)


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable data not refreshing on UI when changing TableModel
 
Similar Threads
JTable ........
JRadioButton in JTable
Problem with JTree inside JScrollPane inside JPanel
JTable
Problem with JTable