0

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

}
}  
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
BulletProof47
  • 54
  • 1
  • 10
  • 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 Nov 20 '13 at 07:02

1 Answers1

1

Use

tblModel.removeRow(rowid);

because the rowid is the converted model index.

René Link
  • 48,224
  • 13
  • 108
  • 140