Removing all the rows of DefaultTableModel

You can set the row count to 0.
setRowCount(0)

Quote from documentation:

public void setRowCount(int rowCount)

Sets the number of rows in the model. If the new size is greater than
the current size, new rows are added to the end of the model If the
new size is less than the current size, all rows at index rowCount and
greater are discarded.

But as you can’t find removeRow either I suspect you haven’t typed you model variable as DefaultTableModel perhaps, maybe just TableModel?

In that case cast your TableModel to DefaultTableModel like this:

DefaultTableModel model = (DefaultTableModel) table.getModel();

Leave a Comment