Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to clear the selection made in a Jlist  RSS feed

 
Kristof Camelbeke
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
 
Manfred Leonhardt
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!