Why is itemStateChanged on JComboBox is called twice when changed?

后端 未结 10 1867
忘掉有多难
忘掉有多难 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:27

    private void dropDown_nameItemStateChanged(java.awt.event.ItemEvent evt) {                                                 
    
    
        if(evt.getStateChange() == ItemEvent.SELECTED)
        {
            String item = (String) evt.getItem();
            System.out.println(item);
        }
    
    }
    

    Good Luck!

提交回复
热议问题