首页 > 技术文章 > 怎么遍历删除表格JTable的行

wwssgg 2021-03-26 14:55 原文

1、遍历删除是没有难,而重点在JTableModel每次删除都是删除0行,因为你删除后,JTableModel就会更新数据了

int tableRowCount = tableModel.getRowCount();
if(tableRowCount > 0){
  int realDeleteRow = 0;
  for(int tableRowIndex=0;tableRowIndex<tableRowCount;tableRowIndex++){
	tableModel.removeRow(realDeleteRow);    //每次都是0行,这是关键
  }
}

  

推荐阅读