开发者

Java ListSelectionListener double change value

开发者 https://www.devze.com 2023-02-14 15:40 出处:网络
I have Java class with JList and ListSelectionListener: final JList myList = new JList(); // ... myList.addListSelectionListener(new ListSelectionListener() {

I have Java class with JList and ListSelectionListener:

final JList myList = new JList();

// ...

myList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent开发者_Go百科 e) {  
                System.out.println("selected");
            }
});

but output is

selected
selected

How should I change my code, that output should be one selected?


Try

         if(e.getValueIsAdjusting())
      {
          System.out.println("Selected");  
      }


Look at getValueIsAdjusting.

Returns whether or not this is one in a series of multiple events, where changes are still being made

Only print "selected" when this method returns false.


You will need to refer to:

getValueIsAdjusting() on the ListSelectionEvent. From the API: Returns whether or not this is one in a series of multiple events, where changes are still being made.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号