I have a JComboBox
and it has an associated itemStageChanged
method. The JComboxBox
is updated in two ways:
- I call
comboBox.setSelectedItem(...)
- The user selects an item in the
comboBox
via my GUI
I want only (2) to initiate an event. What method (e.g., actionPerformed
? changeListener
? itemListener
? etc) should I use that will only catch (2) and not (1). Currently, itemStateChanged
(even with an if
statement to check if it is ItemEvent.SELECTED
) is being called by (1) and (2).
class ItemChangeListener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
//gets in here if user selects an item with their mouse
//or if setSelectedItem is called
}
}
}