• 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

JTable not refreshing with fireTableDataChanged

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After values have been added into the database, the JTable does not display the new data unless I terminate and execute the program again.
Am I supposed to use fireTableDataChanged or newDataAvailable?

I'm using DefaultTableModel:


And the table should refresh after I click the button:



Thanks in advance!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to add the data to the TableModel. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do this. The cell simply needs to be repainted. This is the code from within the extended JTable class and the model variable is the AbstractTableModel I'm using. This code is also applicable to your DefaultTableModel.

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard Valvona, welcome to the Ranch!

In a properly coded application, the model will fire its own updates to notify the view that its data has been changed. The JTable in turn will respond to those updates by repainting the dirty region.

Since you have used the model reference, it's apparent that you are calling that method from outside the model. That indicates a deficiency in your model implementation.

Oh, and did you notice that the question was asked last year?
 
Richard Valvona
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darryl,

Thanks for your feedback. I will admit that I am still quite newish to Java programming despite having done a Masters and then doing work-projects for almost a year. JTables have been quite a challenging area I have found and it's something I'm slowly getting better at.

The reason I chose to store the model in the variable was due to it being a subclass of the main model and that constantly down-casting after using is meant to be quite bad for performance. It's always stored as this variable after calling .

You say that it automatically repaints the dirty region. If that's so then why would even need to exist? In the context of using it, I have made it so that pressing the "delete" button clears the text in a cell just as you would expect in an Excel spreadsheet. It wasn't updating before then so I needed to include it.

Yes, I was aware it's a year old. I couldn't find a similar answer elsewhere and know that people still look at old threads.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic