This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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?
Joined: Jul 18, 2013
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: JTable not refreshing with fireTableDataChanged