JTable Delete All Rows Exception
- by Dimitri
Hi,
I'm trying to delete all entrys from my abstractTableModel. As long as I don't delete the last remaining row, everything works fine, but as soon as I delete this one, I get an ArrayOutOfBoundsException. I'm using a DefaultRowSorter and this seems to be the Exception.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Vector.java:694)
at graphics.tableModel.MyTableModel.getValueAt(MyTableModel.java:78)
at graphics.tableModel.MyTableModel.getColumnClass(MyTableModel.java:90)
at javax.swing.table.TableRowSorter.useToString(TableRowSorter.java:224)
at javax.swing.DefaultRowSorter.updateUseToString(DefaultRowSorter.java:607)
at javax.swing.DefaultRowSorter.sort(DefaultRowSorter.java:556)
at javax.swing.DefaultRowSorter.shouldOptimizeChange(DefaultRowSorter.java:1008)
at javax.swing.DefaultRowSorter.rowsDeleted(DefaultRowSorter.java:866)
at javax.swing.JTable.notifySorter(JTable.java:4262)
at javax.swing.JTable.sortedTableChanged(JTable.java:4106)
at javax.swing.JTable.tableChanged(JTable.java:4383)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
my Code to delete all Rows:
public void deleteAll() {
int size = data.size()-1;
data.clear();
this.fireTableRowsDeleted(0, size);
}
Same thing happens with simply deleting the last existing row.
public void deleteRow(int row) {
data.remove(row);
}
the way i'm calling deleteRow:
for (int i = rows.length - 1; i >=0; i--) {
tm.deleteRow(rows[i]);
}
tm.fireTableDataChanged();
thanks for your help