• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • 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
Hello,

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.
FYI
Here's my listener :

private void veldenListSelected1(javax.swing.event.ListSelectionEvent evt) {
tfVeldNaam.setText((String)veldenList.getSelectedValue());
cbType.setSelectedIndex(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getType());
cbType.setSelectedIndex(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getType());
tfLengte.setText(new Integer(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getLengte()).toString());
veldDetails.setText(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getOmschrijving());

Kristof
 
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:
clearSelection()
method of the JList.
Regards,
Manfred.
 
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
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!