javaswingjtabledefaulttablemodel

Recreate Jtable or remove all rows and add new rows?


I have a JTable and a DefaultTableModel, I want to delete all the rows of JTable every 3 secondes and add new rows to the JTable. Considering the performance, What's the best choice to do that, recreate Jtable or remove all rows and add rows?


Solution

  • What's the best choice to do that, renew Jtable or remove all rows and addrows?

    If you recreate the JTable, all the renderers and editors will be recreated for the table.

    If you change the TableModel, then the table will need to recreate the TableColumnModel, and all the TableColumns based on the new TableModel.

    There will be many more objects that need to be created to support the JTable/TableModel relationship.

    Removing rows and adding rows, will just cause the table to repaint the new data using all the current renderers. I would say this is more efficient. And instead of adding rows one at a time, you should add all the rows at once