我需要从 JTable
中删除行。我写的代码是这样的:
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
int x = 0;
int row = dtm.getRowCount();
while(row>=x){
dtm.removeRow(x);
x++;
}
但它会产生错误,例如:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:
24 >= 24
最佳答案
更简单的解决方案是使用:
dtm.setRowCount(0);
这也更高效,因为在删除所有行后,表只需要重新绘制一次。
关于java - JTable 不删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17382085/