Reputation: 571
I have 2 comboboxes and a spinner, that work like this: if the selected item of the first combo is changed, the second combo keeps its selected item but re-calls the spinner (the spinner is linked only to the second box). My problem is that I can't trigger the stateChange listener of the spinner when I do this.
Here is the code for forcing the second box to reselect its last item when the first one is changed (nothing wrong here, it works just fine):
String orientare = (String) orientareComboBox.getSelectedItem();
orientareComboBox.setSelectedItem(orientare);
This is the code for the second box actionListener:
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
String value = combo.getSelectedItem().toString();
if (value.equalsIgnoreCase("oblica"))
{
unghiSpinner.setEnabled(true);
double unghi = (double) unghiSpinner.getValue();
unghiSpinner.setValue(new Double(unghi));
}
}
And the spinner's Listener:
public void stateChanged(ChangeEvent e)
{
if (unghiSpinner.isEnabled())
{
// do something
}
}
I do not know what command I should use for unghiSpinner
to trigger its listener, because setValue()
can't do it.
Upvotes: 2
Views: 1718
Reputation: 285403
I don't see you changing the value of your JSpinner in the code above. It appears that all you do is set the spinner's value to the same value that it held previously, and that shouldn't trigger the listener. To trigger a change listener to fire you must change the state of the observed entity.
Upvotes: 5