• 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

How to clear the selection made in a Jlist

Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is it possible before adding a new element to the Jlist to "clear" the already made
selection in the Jlist ?
That would solve my problem I'm having.
Because when I already have made a selection in the Jlist and then add a new element, the
ListEvenListner doesn't know where the index is anymore.
I always get an exception java.lang.ArrayIndexOutOfBoundsException -1.
I do not have this problem when I add a new element without having selected something in the
Jlist first.
Only when I select something by means of a mouseclick, then I get an exception when adding a
new elment.
Hope this is clear.
I also work with a defaultListmodel which contains the data of the list and with a Vector which
contains the other data necessary to fill other Jtextfields.
Thanks for any reply.
Here's my listener :

private void veldenListSelected1(javax.swing.event.ListSelectionEvent evt) {
tfLengte.setText(new Integer(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getLengte()).toString());

Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kristof,
If by clearing the selection you mean just remove the hilighting then you just need to call the:
method of the JList.
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
create, convert, edit or print DOC and DOCX in Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!