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?
views:
176answers:
1
+1
A:
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
2008-12-11 15:24:39
? Do you not agree?
jjnguy
2008-12-11 19:59:32
I hoped to see something more... original.
michelemarcon
2008-12-15 07:44:44
Oh, sorry. I wouldn't bother thinking of a more imaginative way of doing it. THis works and is fairly quick.
jjnguy
2008-12-15 13:04:52