tags:

views:

1136

answers:

1

I've tried this:

public void removeSelectedFromTable(JTable from)
{
 int[] rows = from.getSelectedRows();
 TableModel tm= from.getModel();

 while(rows.length>0)
 {
  ((DefaultTableModel)tm).removeRow(from.convertRowIndexToModel(rows[0]));

  rows = from.getSelectedRows();
 }
 from.clearSelection();
}

But, it sometimes leaves one still there. What can be the problem?

A: 

Why not just use this,

public void removeSelectedFromTable(JTable from)
{
        int[] rows = from.getSelectedRows();
        TableModel tm = (DefaultTableModel) from.getModel();


        for (int row : rows) {
         tm.removeRow(from.convertRowIndexToModel(row));
        }

        from.clearSelection();
}
Chantz