In my Swing application, the user must insert numbers and values, before switching to the next window. Now as a clean program should, I check every input if its valid or not
I prefer to use an improved version of JFormattedTextField
. By improved I mean better caret behavior, validation on each change to provide immediate user feedback (e.g. change background color when input is invalid), ... . That combined with a button which is disabled until the input is valid.
Main benefits over the "click the button and see error messages appear":
InputVerifier
which just avoids changing focusFormat
s (for dates, doubles, integers, ranges, ... ) and you can handle almost any situationFormat
s, easy adjustable for different Locale
sJFormattedTextField
. All the parsing code is contained in the format, and you can simply use JFormattedTextField#getValue
JFormattedTextField
. You know that the value you retrieve using getValue
is a valid one