当我从JTable中删除选定的行时,它的工作正常但是如果我按某种顺序对行进行排序,那么它的tblModel.removeRow()
会以错误的顺序删除该行。
请帮忙。谢谢。
//Storing the selectedrows into rows[]
int[] rows = userTable.getSelectedRows();
for (int a = rows.length-1 ; a >= 0; a--) {
//Converting the rowindex to model row index
int rowid= userTable.convertRowIndexToModel(rows[a]);
//Converting the rowindex to model column index
int colid= userTable.convertColumnIndexToModel(0);
if(um.deleteUser((int) tblModel.getValueAt(rowid, colid))==true){
//Everything is good upto here but this line removes the wrong row if the row is sorted
tblModel.removeRow(rows[a]);
JOptionPane.showMessageDialog(null,"Deleted");
MyDashboard d = new MyDashboard();
d.setStatusText("Deleted");
}
}
答案 0 :(得分:1)
使用
tblModel.removeRow(rowid);
因为rowid
是已转换的模型索引。