I want to clear all rows in a custom TableModel. Unfortunately, a custom TableModel in Java does not allow use of most efficient of row clearing methods, which only applies to a DefaultTableModel like that shown below:
myTableModel.getDataVector().removeAllElements();
myTableModel.fireTableDataChanged();
To do an all clear like the above, for a custom TableModel, you need to reset the TableModel like that shown below:
myTableModel = new MyTableModel();
myTable.setModel(myTableModel);
If there are no rows in the custom TableModel, it throws an Array out of bounds exception
try {
myTableModel = new MyTableModel();
myTable.setModel(myTableModel);
} catch (Exception ex) {
System.err.println(ex.getMessage());
}