简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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