When I press the Delete button, it fires actionPerformed and deletes that row from the table. And when I select a row, it fires valueChanged and shows the toString() method's value of the selected object in the textarea.
However, whenever I delete a row valueChanged is also called, giving me an ArrayOutOfBoundsException, I assume because the row is deleted and getselectedRow() now returns -1.
I could use two different private classes, one for ActionListener and one for ListSelectionListener, but since this is for an exam project, we are supposed to put it all into one private class.
Therefore my question is how I avoid firing valueChanged when I delete a row, or how else I can fire an event when I select a row. I would prefer not to use mouseClicked and similar methods.
Right now I'm using this if to check if a row has been selected, as opposed to a column or cell which I don't need to do anything about.
if (e.getSource() == tblPars.getSelectionModel() && tblPars.getRowSelectionAllowed())
{
...
}


Sign In
Create Account


Back to top









