• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

ListSelectionlistener problem when adding new elements

Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
Subject says it all.
I received help to clear the Jlist selection !
thanks Manfred !!
But I still get an exception in the ListSelectionListener when I add a new element to the Jlist.
The problem I'm having is situated in the ListSelectionListener where I set the elements which are inside a vector to the selected item in the Jlist.
This works veryw well EXCEPT when I add a new element to the Jlist.
When adding a new element I receive an exception like this :
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: -1 < 0
at java.util.Vector.elementAt(Vector.java:427)
at veld.VeldGUI.veldenListSelected1(VeldGUI.java:236)
at veld.VeldGUI.access$300(VeldGUI.java:23)
at veld.VeldGUI$4.valueChanged(VeldGUI.java:128)
at javax.swing.JList.fireSelectionValueChanged(JList.java:946)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:960)
I thought with clearing the selection in the list I could solve this but it doesn't work.
I probably have to do something in the listener.
Does anybody have any advice to solve this problem?
Should I work with a Datalistener ?
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kristof,
Not exactly clear on what you are doing, but this might or might not help you. The ListSelectionListener actually gets called twice for each user selection. You should use the method isValueAdjusting to make sure you only run your code once and not twice. That might actually be your problem (i.e., the double call could be screwing you up). Example:

You've gotta fight it! Don't give in! Read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!