JList - deselect when clicking an already selected item

后端 未结 6 1746
忘掉有多难
忘掉有多难 2020-12-10 04:36

If a selected index on a JList is clicked, I want it to de-select. In other words, clicking on the indices actually toggles their selection. Didn\'t look like this was suppo

6条回答
  •  隐瞒了意图╮
    2020-12-10 04:59

    You could always the ListSelectionListener instead of deciphering the point clicked and then translating it to the item selected.

    http://java.sun.com/docs/books/tutorial/uiswing/examples/events/index.html#ListSelectionDemo

    http://java.sun.com/docs/books/tutorial/uiswing/events/listselectionlistener.html

    http://java.sun.com/docs/books/tutorial/uiswing/examples/events/ListSelectionDemoProject/src/events/ListSelectionDemo.java

    In the above link for java file there is an implementation which can be easily improved to do "deselection" :)

提交回复
热议问题