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 and the fly likes JList deleting multiple items Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList deleting multiple items" Watch "JList deleting multiple items" New topic
Author

JList deleting multiple items

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Maybe I didn't explain the situation good enough. Here goes round two.
I have a vector which feeds a JList. Each item is a String and I allow the JList to have multiple selections. I have a delete button which gets the selection indices and then attempts to delete the selected items from the vector. Problem is that it will always get an ArrayOutOfBoundsException when doing multiple removes. Can somebody please look at this code and see if you can help me delete multiple selections from my JList.
Thank you.
CODE BELOW:

[ October 12, 2002: Message edited by: Frank Hale ]
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi Frank,
I think, the problem is the way, haw you delete the entries in your data vector. If you remove multiple elements from it, then you may run in problems if you start from the beginning. In your case, you should start at the end.

Imagine a vector with 3 elements, where you want to delete the first and the last. In your case, you start with the first, this goes well, but when you want to delete the last, the index of the last has already changed, so you will delete an element, which doesn't exist. This is the reason for your exception.
Hope that helps

Rene
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Rene,
Thank you for the help. This works great!!! Thanks a million....
Frank
 
 
subject: JList deleting multiple items