Search code examples
javaswingjtableabstracttablemodel

Which one is better : AbstractTableModel.fireTableDataChanged() or AbstractTableModel.fireTableRowInserted()


Is it a good idea to add one row and call fireTableRowInserted() or adding all rows and then call fireTableDataChanged()?


Solution

  • If all you do is adding new rows, it's better to add all the rows, and call fireTableRowsInserted() with the appropriate first and last rows. The view will have to handle only one event, and the event tells exactly what happens, which avoids refreshing the parts of the view that don't need to be refreshed.