Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deselect Jlist item on some event in java

could any one suggest me any method or any other way in java that i could deselect my jlist item when some event occurs? i tried this but this does not seem to work

myJList.setSelectedIndex(-1);
myJList.ensureIndexIsVisible(-1);
like image 430
Jony Avatar asked Mar 07 '12 05:03

Jony


People also ask

What is JList in Java Swing?

JList is part of Java Swing package . JList is a component that displays a set of Objects and allows the user to select one or more items . JList inherits JComponent class.

Which interface is implemented in JList in Java?

Simple, dynamic-content, JList applications can use the DefaultListModel class to maintain list elements. This class implements the ListModel interface and also provides a java.

How do you add to a JList?

addElement(new item); and it will show up in the JList. (You can also use add(int index) where you specify the 0-based position of the element to be added.)


1 Answers

Try myJList.clearSelection(); It clears the selection(s) on your JList object. If multiple list items selected together, they can also be deselected via this method.

like image 183
Juvanis Avatar answered Sep 21 '22 09:09

Juvanis