• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to clear the selection made in a Jlist

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic