簡體   English   中英

如果對JTable進行排序,則TableModel RemoveRow()刪除錯誤的行

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

當我從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");

}
}  

采用

tblModel.removeRow(rowid);

因為rowid是轉換后的模型索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM