18

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);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jony
  • 1,035
  • 7
  • 17
  • 43
  • trying random api rarely is a good solution strategy (why would you thing that ensureIndexIsVisible has anything to do with selection?) - instead read the api doc and/or a good basic tutorial, f.i. the online swing tutorial linked to in the swing tag description – kleopatra Mar 07 '12 at 10:15

1 Answers1

42

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.

Juvanis
  • 25,802
  • 5
  • 69
  • 87
  • Hello Deporter please read my This Question about loading a .Tif Image and please suggest me how to do it? i had put my code also which i tried [http://stackoverflow.com/questions/9634472/how-to-set-tif-image-to-imageiconin-java] – Jony Mar 09 '12 at 13:08
  • @AshishDonvir ok i will take a look at it now. – Juvanis Mar 09 '12 at 13:09