Why is itemStateChanged on JComboBox is called twice when changed?

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

    Quote from Java Tutorial:

    "Only one item at a time can be selected in a combo box, so when the user makes a new selection the previously selected item becomes unselected. Thus two item events are fired each time the user selects a different item from the menu. If the user chooses the same item, no item events are fired."

提交回复
热议问题