Skip to main content

Removing rows from table model

2 replies [Last post]
Joined: 2010-03-26

This method is very slow for removing rows from table model. Is there better way?

Most rows in table model are old and i need to repopulate. Many of them would have disappeared. So I want to remove them all and rows from the master source again.

static void clearTableModel(DefaultTableModel md) {

while ( md.getRowCount() > 0 ) {




Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-04-17

Use defaultTableModel.setRowCount(0) to clear it or call setDataVector directly with the new data.

Joined: 2005-08-27

It's a little unclear what is happening to the master source here.
What you are doing does not affect the master source

Assuming the master source is being updated first, calling model.fireTableDataChanged()
should cause the table to redraw itself.