Java – How to deselect Jlist item on some event in java

javajlistselectionswing

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

Best Answer

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.