I have two JComboBox
in a form and I added an ItemListener
to them and I should overwrite itemStateChanged()
, now I wanna say if the first JComboBox
items selected do something and else if the second JComboBox
items selected do another thing, but I don't know how? Maybe code can help you.
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange()==ItemEvent.SELECTED)
picture.setIcon(pics[box.getSelectedIndex()]);
}
In the second line of code I don't know how to recognize which JComboBox
state has changed.
You can use ItemEvent#getSource()
Example:
Now for distinct
combo1
fromcombo2
, you have 2 options , you can set names to that components like this.And in the itemListener
Or if you know that they are the same instance, then you can always use
==
.