Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtable IndexOutOfBoundsException when remove all  RSS feed

 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I am trying to remove all rows from my JTable model, my model is inhariting the DefaultTableModel, I keep getting : IndexOutOfBoundsException

First method I tryed :


it gave me :
java.lang.ArrayIndexOutOfBoundsException: 2 >= 1
message = AWT Exception
at java.util.Vector.removeElementAt(Vector.java:511)
at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:446)


I tryed also:


this gave me the error:
message = AWT Exception
java.lang.IndexOutOfBoundsException: bitIndex < 0: -1
at java.util.BitSet.get(BitSet.java:441)
at javax.swing.DefaultListSelectionModel.clear(DefaultListSelectionModel.java:257)
at javax.swing.DefaultListSelectionModel.setState(DefaultListSelectionModel.java:567)
at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:635)
at javax.swing.JTable.tableRowsDeleted(JTable.java:4446)
at javax.swing.JTable.tableChanged(JTable.java:4349)

What am I doing wrong?
Thank you
Sharon
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code, after you call removeRow(i) when i==0, the getRowCount() for the next iteration is decremented.
Try something like:
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it!!! I forgot about the underlying vector...
Working great!
Thank you
Sharon
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also do it in reversed order, starting at count - 1 and going on until 0.

Of course you can always call setRowCount(0), which will also clear everything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!