This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JTable data not refreshing on UI when changing TableModel  RSS feed

 
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
 
Author
Ranch Hand
Posts: 964
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!