Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 e) {  
                System.out.println("selected");
            }
});

but output is

selected
selected

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

like image 954
Martynas Avatar asked Mar 18 '26 18:03

Martynas


1 Answers

Try

         if(e.getValueIsAdjusting())
      {
          System.out.println("Selected");  
      }
like image 113
Bala R Avatar answered Mar 20 '26 07:03

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!