How can I limit input of digits using jSpinner as a time picker?
When I use this code:
JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm");
DateFormatter formatter = (DateFormatter)editor.getTextField().getFormatter();
formatter.setAllowsInvalid(false); // this makes what you want
formatter.setOverwriteMode(true);
I took this example from here: Similar problem using jSpinner as time picker on StackOverflow
So when I start typing right at the beginning 1111, then it works fine until I enter further digits, then it starts calculating and giving me "strange" output, like:
12:51
when I entered another 1 after 1111.
When I put 12h
time format, like:
JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm a");
then it works just fine, stopping at the end after forth digit and not allowing any other input. How can I get this behavior for 24h time format?