简体   繁体   English

如果对JTable进行排序,则TableModel RemoveRow()删除错误的行

[英]TableModel RemoveRow() removing wrong row if JTable is sorted

When I remove the selected rows from the JTable its working fine but if I sort the row in some order then its tblModel.removeRow() is removing the row in wrong order. 当我从JTable中删除选定的行时,它的工作正常,但是如果我按某种顺序对行进行排序,则其tblModel.removeRow()会以错误的顺序删除行。

Please help.Thanks. 请帮忙。谢谢。

//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");

}
}  

Use 采用

tblModel.removeRow(rowid);

because the rowid is the converted model index. 因为rowid是转换后的模型索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM