File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes Deleting The Whole Table problem(Index Out Of Bounds) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Deleting The Whole Table problem(Index Out Of Bounds)" Watch "Deleting The Whole Table problem(Index Out Of Bounds)" New topic
Author

Deleting The Whole Table problem(Index Out Of Bounds)

michael johanson
Greenhorn

Joined: Feb 08, 2010
Posts: 3


the compiler throws me an index out of bounds, i cant find the reason why im getting this, so I tried to remove piece by piece the whole code, until I ended up in this..
but still I cant solve this problem..

when I select all the rows in the Table and press the delete button, it deletes 99% of it, and there is one remains, and an IndexOutOfBoundsException throws me, help with this please
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

1) Don't use getSelectedRow(); use the real rows that are selected.

2) If you remove a row, all later rows will have their indexes decreased by one. You can prevent this by iterating backwards:
This code does assume that selectedRows will be sorted. If you want to make sure, call Arrays.sort before you start iterating.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
michael johanson
Greenhorn

Joined: Feb 08, 2010
Posts: 3
thank you so much!

learned again!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 7059

"mykel java"

Please check your private messages for an important administrative matter

This message was edited 1 time. Last update was at by Maneesh Godbole



[Donate a pint, save a life!] [How to ask questions]
 
 
subject: Deleting The Whole Table problem(Index Out Of Bounds)
 
MyEclipse, The Clear Choice