How can I make the JSpinner
go back to the last valid value when it loses focus and also when I press the spinner arrow button?
Asked
Active
Viewed 158 times
-2

Andrew Thompson
- 168,117
- 40
- 217
- 433

choymns
- 17
- 1
- 2
-
add some valid code demonstrating your problem – nachokk Dec 25 '13 at 21:25
-
*"last valid value"* 1) What conditions determine what is valid? 2) Why not simply supply a `SpinnerModel` that only has valid values? 3) For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Dec 25 '13 at 21:27
-
This question appears to be off-topic because it is about a matter the OP seems to have abandoned. – Andrew Thompson Dec 26 '13 at 15:36
-
@AndrewThompson, maybe the OP is busy celebrating christmas :-) With some more details it might become an interesting question. – KarlP Dec 27 '13 at 00:44
-
@KarlP Then maybe the OP should have delayed asking the question until they had time to attend to it. – Andrew Thompson Dec 27 '13 at 03:25
1 Answers
2
You could use an InputVerifier
or adjust the spinner model to provide min/max values. See How to use Spinners

MadProgrammer
- 343,457
- 22
- 230
- 366
-
*"adjust the spinner model to provide min/max values"* Note that 'valid values' might be `{1,3,7}` ;) – Andrew Thompson Dec 25 '13 at 21:32
-
1@AndrewThompson While I have no doubt of the truth of the comment, when the OP chooses to put more effort into their question, I'll put more effort into my answer ;) – MadProgrammer Dec 25 '13 at 21:44
-
-
AFAIK not possible only by using DocumentFilter/DocumentListener (returns JFormattedTextField by default, but is possible to cast to JTextField) this issue is the same for number, date ........ – mKorbel Dec 26 '13 at 13:42