aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable not refreshing with fireTableDataChanged Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable not refreshing with fireTableDataChanged" Watch "JTable not refreshing with fireTableDataChanged" New topic
Author

JTable not refreshing with fireTableDataChanged

Lily Tan
Greenhorn

Joined: May 01, 2012
Posts: 3
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!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

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.

luck, db
There are no new questions, but there may be new answers.
Richard Valvona
Greenhorn

Joined: Jul 18, 2013
Posts: 2
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

Joined: May 03, 2008
Posts: 4664
    
    5

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

Joined: Jul 18, 2013
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable not refreshing with fireTableDataChanged