Deleting all the rows in a JTable

前端 未结 12 717
生来不讨喜
生来不讨喜 2020-12-09 02:38

I need to remove all the rows in my JTable.

I have tried both of the following:

/**
 * Removes all the rows in the table
 */
public void clearTable()         


        
12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 03:23

    I had multiple tables, so I created a method to clear "any" table:

    private void deleteAllTableRows(JTable table) {
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        while( model.getRowCount() > 0 ){
            model.removeRow(0);
        }
    }
    

提交回复
热议问题