A DESCRIPTION OF THE PROBLEM :
There are three typos in the example given at the top.
1. Remove the second left brace in the " catch ... " line.
2. Terminate " JComponent editor = spinner.getEditor() " with a semicolon.
3. A closing parenthesis is missing before the semicolon in
" ((DefaultEditor)editor).getTextField().setValue(spinner.getValue(); "
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
try {
spinner.commitEdit();
}
catch (ParseException pe) {
// Edited value is invalid, spinner.getValue() will return
// the last valid value, you could revert the spinner to show that:
JComponent editor = spinner.getEditor();
if (editor instanceof DefaultEditor) {
((DefaultEditor)editor).getTextField().setValue(spinner.getValue());
}
// reset the value to some known value:
spinner.setValue(fallbackValue);
// or treat the last valid value as the current, in which
// case you don't need to do anything.
}
return spinner.getValue();
ACTUAL -
See above.
URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/7/docs/api/