How do I add MouseListeners to JList items?

后端 未结 1 1234
暖寄归人
暖寄归人 2021-01-26 06:06

So, what I want, is for when a JList item is selected, for another bit of code to run. But my question is, how do I implement MouseListeners for specif

相关标签:
1条回答
  • 2021-01-26 06:42

    If you want something to happen when the selection changes, you don't want a MouseListener, but a ListSelectionListener. Not only is it the right abstraction, but remember that the selection can change without using the mouse. Most computer have a keyboard these days.

    How to use one is described in the Swing tutorial.

    Inside your listener, get the element that is selected, and act accordingly.

    0 讨论(0)
提交回复
热议问题