Why is itemStateChanged on JComboBox is called twice when changed?

后端 未结 10 1892
忘掉有多难
忘掉有多难 2020-12-03 09:32

I\'m using a JComboBox with an ItemListener on it. When the value is changed, the itemStateChanged event is called twice. The first call, the ItemEvent is showing the origin

10条回答
  •  感动是毒
    2020-12-03 10:11

    Yo can do it like this:

    import java.awt.event.*;
    
    jComboBox1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Hello");
            }
        });
    

提交回复
热议问题