GeeCON Prague 2014*
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


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: 19697
    
  20

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: 10425
    
    8

"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!]
 
GeeCON Prague 2014
 
subject: Deleting The Whole Table problem(Index Out Of Bounds)