Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable data not refreshing on UI when changing TableModel

 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brian Cole
Author
Ranch Hand
Posts: 923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!