I'm using the following code for the listener and although when I check the value of the selected Row it shows the correct index, when I call the tblmodel.removeRow() method it throws an exception -1 ....
public void valueChanged(ListSelectionEvent e){
if(e.getSource() == tbl.getSelectionModel() && tbl.getRowSelectionAllowed()){
// Get the data model for this table
//TableModel model = (TableModel)tbl.getModel();
// Determine the selected model
int selectedRowIndex = tbl.getSelectedRow();
String id = (String)tblmodel.getValueAt(tbl.getSelectedRow(),0);
String value = (String)tblmodel.getValueAt(tbl.getSelectedRow(),tbl.getSelectedColumn());
// Display the selected item
if (! e.getValueIsAdjusting()){
if(value.equals("Delete")){
if(JOptionPane.showConfirmDialog(null,"Are you sure you want to delete account no "+id + "\n Row Index: " + selectedRowIndex + "\nModel Row Count : "+tblmodel.getRowCount(), "Confirmation",JOptionPane.OK_CANCEL_OPTION)==0){
try {
deleteAccount(id);
tblmodel.removeRow(selectedRowIndex);
}
catch (ArrayIndexOutOfBoundsException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "Returned Row Index is : " + selectedRowIndex, "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
}
//JOptionPane.showMessageDialog(null,"The Value recieved is : "+id + "-"+value, "Value Recieved", JOptionPane.PLAIN_MESSAGE);
}
}
}