How to deselect Jlist item on some event in java

Jony picture Jony · Mar 7, 2012 · Viewed 19.6k times · Source

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);

Answer

Juvanis picture Juvanis · Mar 7, 2012

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.