• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

JList deleting multiple items

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rene,
Thank you for the help. This works great!!! Thanks a million....
Frank
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic