How to undo changes on JSpinner?
Question
I need to validate the user input of a JSpinner
, and if invalid, I need to undo (rollback) the value change. What is the best way to do it?
Solution
Well, if you save the old value from the last time you validated the input, you can then reset the value of the spinner back to the last valid value.
boolean valid = validate(spinner);
if (valid)
validValue = spinner.getValue();
else
spinner.setValue(validValue);
Maybe something like that.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow