1
votes

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
I made another button "Delete Row" The Event: DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); model.removeRow(jTable1.getSelectedRow()); jtable1.setModel(model); This button causes the same Execption to be thrown. - Jake Brasch
for better help sooner post an SSCCE with hardcoded value (as local variable) for DefaultTableModel, there are four possible issues, wrong notifiers in TableModel, replacing JTable, code lines inside ListSelectionListener, some ZOO in Renderer, or their free_styled combinations, meaning runnable, compilable code, btw tons on this forum - mKorbel
please edit your question and the additional details (instead of trying it in an comment which is near-to unreadable) - kleopatra

1 Answers

2
votes

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