posted 23 years ago
I have a JTable with row selection listener handled by the following code.
Say I select row 2 of the table: After selecting the row, the method getSelectedTeam() goes off and does its thing okay,
but upon then returning to the original table, row 2 remains selected and therefore I cannot select it again... I can't figure out how to enable reselection of a row.
I have tried the clearSelection() method as commented out in the code, which appears to work but throws an arrayIndexOutOfBoundsException.
Can somebody help please?
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Choose only 1 team at a time
ListSelectionModel cellSelectionModel = table.getSelectionModel();
cellSelectionModel.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
if(!e.getValueIsAdjusting()){
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
selectedRow = lsm.getMinSelectionIndex();
System.out.println("Row " + selectedRow + " is now selected.");
getSelectedTeam();
// lsm.clearSelection();
}
}
});