I've got a JComboBox on which i've set a listener.
The problem is that Java enter into the listener code whatever action is done on the combobox (state changed).
I would like Java enter into this code only when the active value of the combo box is changed (and not
during the selection, when the list is open).
What kind of a listener did you add?
What do you mean by the 'active value' of the combobox?
Do you mean the selected item?
Do you mean you want to trap when characters are typed into the editbox?
Dave
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
The string tempo is always the same message.
I just want to trap the value when the user has selected one in the list, but only that. The fact is that
the action listener execute the code even when the user type some characters in the editbox....so each time
he type characters, code is executed....
If you just want notification of changes of the selected item, add an ItemListener:comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent event) {
int stateChange = event.getStateChange();
if (stateChange == ItemEvent.DESELECTED) {
System.out.println("Combo item deselected");
}
else if (stateChange == ItemEvent.SELECTED) {
System.out.println("Combo item "+ comboBox.getSelectedIndex() + " selected");
}
}
});
Dave
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Bookmarks