JavaRanch » Java Forums »
Java »
Swing / AWT / SWT / JFace
| 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: 18365
|
|
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: 7602
|
|
"mykel java"
Please check your private messages for an important administrative matter
|
[Donate a pint, save a life!] [How to ask questions]
|
 |
 |
|
|
subject: Deleting The Whole Table problem(Index Out Of Bounds)
|
|
|
|