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?
Asked
Active
Viewed 868 times
0

jjnguy
- 136,852
- 53
- 295
- 323

michelemarcon
- 23,277
- 17
- 52
- 68
1 Answers
1
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.

jjnguy
- 136,852
- 53
- 295
- 323
-
I hoped to see something more... original. – michelemarcon Dec 15 '08 at 07:44
-
Oh, sorry. I wouldn't bother thinking of a more imaginative way of doing it. THis works and is fairly quick. – jjnguy Dec 15 '08 at 13:04