Skip to main content

always get exceptions after deleting the last row in the jxtable.

Please note these forums are being decommissioned and use the new and improved forums at
4 replies [Last post]
Joined: 2012-01-05


For some reason i always get the following error after trying to delete the last row in the jxtable

when I found the data in the row that I would do the following to delete, I call

arrayList.remove(z); fireTableRowsDeleted(z,z);

and then the event gets forwarded to getValueAt, in this function I am checking whether the call is trying to access to the data where it doesn't exist in the model, which it doesn't in this case! ( just removed)
so I returned ""; and then the exception happens. My question is when knowing the data model returns zero

public int getRowCount() {
return arrayList.size();

why does it still forward the fireTablerowsDeleted call to getValueAt ? am I missing something here ? thank you.

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: valid viewIndex: 0 <= index < 0 but was: 0
at org.jdesktop.swingx.sort.DefaultSortController.convertRowIndexToModel(
at javax.swing.JTable.convertRowIndexToModel(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at org.jdesktop.swingx.JXTable.prepareRenderer(
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-06-08

A small, runnable demo is required for more debugging efforts.


Joined: 2003-06-12

Is it me or you edited your comment and replaced showTable by arrayList ?
How about posting a complete working example if you need help...

Joined: 2003-06-12

Hi. I would suggest you try to find a good example of how to design around a JTable and its Data Model. The lines of code you have are all wrong ;-(.

Here are some pointers :

1. Try to not access the JXTable (showTable ?) from your model.
2. Use a collection inside your model for your data.
When its time to delete, delete the row from inside your model : collection.remove(element);
3. Then fire the event. the event is only for the UI stuff.
4. getRowCount() should return the size of your internal data collection. Do not use a reference to JXTable there. (JXTable could be filtering rows for example).

Here is a quick sample from some more or less good code I did recently.
I don't have a delete in that example, but there is a clear() method on the model that
do the same.

Also, this is not really a swingx question ;-)

Joined: 2012-01-05

well, showTable is acutally a list of string[], i just changed the name to arrayList, sorry for the confusion.