0
votes

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

}
}  
1
Please do not put "Solved" in your title. This isn't a support forum. Posts remain here for others to see - and perhaps offer better/updated answers in the future.Andrew Barber

1 Answers

1
votes

Use

tblModel.removeRow(rowid);

because the rowid is the converted model index.