novicePrgrmr
novicePrgrmr

Reputation: 19395

How to clear a custom TableModel that extends AbstractTableModel

Exactly what the question states. I created a custom tableModel class and I want to clear the JTable associated with that model on an actionPerformed.

Upvotes: 0

Views: 3193

Answers (1)

Umesh Kacha
Umesh Kacha

Reputation: 13686

You must remove the data from the TableModel used for the table.

If using the DefaultTableModel, just set the row count to zero. This will delete the rows and fire the TableModelEvent to update the GUI.

JTable table;

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

model.setRowCount(0);

If using other TableModel please check the documentation.

Upvotes: 2

Related Questions