Possibly remove ListSelectionListener before clearing Jtable (runtime)?

1.4k Views Asked by At

I have written a ListSelectionEvent for my jTable.

It works to take values from specific cells and put the value into the cells corresponding jTextField.

So, I upload a CSV file to the jTable. It loads.

I click the button at the bottom labeled "Clear Table". The table is cleared and a new blank row is made (I couldn't get around doing this. Otherwise it wouldn't let me load another CSV file)

My problem :: I load another CSV File. It loads. I select a row, the listSelectionEvent fires, and executes as it should. I click "Clear Table" and it throws this Exception.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1

After this the program starts bugging out and needs to be closed. The jTable does clear when the window is resized.

Thanks in advance for help with this.

JB

1

There are 1 best solutions below

4
On

Before you do any calls to the model using table.getSelectedRow(), you should first check if this value is >= 0.