This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Deleting The Whole Table problem(Index Out Of Bounds) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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
Sheriff

Joined: Oct 27, 2005
Posts: 19908
    
  23

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 - OCEEJBD 6
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: 10651
    
    9

"mykel java"

Please check your private messages for an important administrative matter


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deleting The Whole Table problem(Index Out Of Bounds)