开发者

Java ListSelectionListener double change value

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜