I created a component JSpinnerwith SpinnerNumberModelas a model:
JSpinner spinbox = new JSpinner(new SpinnerNumberModel(2, 1, 7, 1));
I added a listener to detect changes.
spinbox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
synchronized (this) {
System.out.println("New value: " +
((Integer)_spiNumOfAIs.getValue()).intValue());
}
}
});
All I see is this:
New value: 0
New value: 0
Am I reading the spinbox value incorrectly?
If you are curious about the block synchronized: I am new to Swing, and I don’t know whether the executors of the actions are executed in the same thread where I created my own JDialogor not, that's why I put threads for all action listeners in order to ensure security. _spiNumOfAIsis a member variable.
: , ... , JSpinner spinbox, JSpinner _spiNumOfAis, - , .