Java ListSelectionListener double-change value

I have a Java class with JList and ListSelectionListener:

final JList myList = new JList();

// ...

myList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {  
                System.out.println("selected");
            }
});

but conclusion

selected
selected

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

+3
source share
3 answers

Try

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

Take a look at getValueIsAdjusting .

Returns whether this is one of a series of several events where changes are still being made

Only print "selected" when this method returns false.

+2
source

:

getValueIsAdjusting() ListSelectionEvent. API: , , .

+1

Source: https://habr.com/ru/post/1795487/


All Articles