Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fireTableDataChanged() java

Why does my model update the JTable view even if I do not call the fireTableDataChanged() ? Is this normal behaviour?

@Override
public void updateGUI(GUIUpdateEvent obj)
{
    System.out.println("updategui");
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            data[i][j] = obj.getBoard()[i][j].getCurrentPawnOnField().getChessIcon();
        }
    }
    //fireTableDataChanged();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you have a JTable that is bound to a TableModel and the underlying data in the model changes, the table can automatically update its view to reflect these changes without explicitly calling fireTableDataChanged() or any other table model update method.
Its known as automatic refreshing or automatic data Sync between the JTable and the TableModel.

I think the reason for this behavior is that the JTable listens for changes in the associated TableModel.
When the data in the model changes (for example, when you modify the data array in your code), the JTable is notified of these changes, and it automatically updates its view to reflect the new data.

This behavior is part of the default functionality provided by Swing’s JTable. You don’t always need to call fireTableDataChanged() manually unless you want to have more control over when the table view updates or if you’re using a custom TableModel implementation.

fireTableDataChanged() method call in your code, it will still work, but it may be unnecessary in this case !

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading