Find selected item of a JList and display it in real time

后端 未结 3 1441
-上瘾入骨i
-上瘾入骨i 2020-12-14 19:13

I have a JList, where i am displaying some ID\'s. I want to capture the ID the user clicked and dis play it on a JLabel.

String sel         


        
3条回答
  •  天命终不由人
    2020-12-14 20:04

    Use a ListSelectionListener:

    JList list = new JList(...);
    list.addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent evt) {
        if (!evt.getValueIsAdjusting()) {
          // code here
        }
      }
    });
    

提交回复
热议问题