How to remove all rows from a Java JTable created using Custom TableModel

To remove all rows from a Java JTable created using Custom TableModel, try the following:

MyModel myTableModel = (MyModel) myTable.getModel();
for (int i = myTableModel.getRowCount()-1; i >= 0; i--) myTableModel.deleteRow(i)
;

Define the deleteRow(int row) method in the MyModel class.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s