• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to update JTable Data???

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am a bit frustrated at this point. When doing a retrieve in my app, I am able to correctly populate my JTable with data. If I go in a second time and do another retrieve the data is correct, but it does not populate/refresh the JTable. I am using the AbstractTableModel and I have TableModelListeners on my Gui class. I can see the new data for a second or two in the JTable and then the table reverts back to the first requests' data. I also do a repaint() after each retrieve.
Any suggestions are welcome !!!
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you calling fireTableDataChanged() from your table model methods?
 
Pervez Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sai,
I've tried calling fireTableCellUpdated() as well as fireTableDataChanged(). Is there a specific method I should be calling this from. Right now I'm calling it from the setValueAt().
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you pass the data to the JTable, which method are you using?
You shouldn't have to issue a repaint.
You can create a new instance of your table model with the new data, and then call setModel. like this.

Mark
 
Pervez Ahmed
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
I am creating a new instance of my data model just as you have mentioned. The data in the model is correct, but the JTable refuses to refresh itself with the new data.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pervez,
I am not sure why your JTable is not refreshing with the new data. But you can check the items below. Obviously something is wrong.
1) When you create the table, put it in a JScrollPane
2) Create one instance of the table model and assign to the JTable during instantiation
3) When you get the new data, assign the new data to the table model. Below is the sample code:

Good luck!
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Sai what's fireTableDataChanged();
I didn't have that in my code and it displayed my data fine.
Hmm. I wonder what I did? I just did setModel and then it would display without firing anything.
Oh well, if it works for you with it, and doesn't without it, then you guys need it.
Mark
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
My model extended AbstractTableModel. That's why I needed it. Yours probably extended DefaultTableModel, right?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope mine extends AbstractTableModel too.
Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic