JFormattedTextField : input time duration value
- by bguiz
I want to use a JFormattedTextField to allow the user to input time duration values into a form. Sample valid values are:
2h 30m
72h 15m
6h
0h
However I am having limited success with this. Can some one please suggest how this can be accomplished? I am OK if this result can be achieved using a JTextField as well.
Thanks!
If it is worth anything, here's my current attempt:
mFormattedText.setFormatterFactory(
new DefaultFormatterFactory(
new DateFormatter(
new SimpleDateFormat("H mm"))));
This sorta works except that:
I cannot get h and m to appear as plain text (I tried escaping) *
The number of hours has a max
*: See @nanda's answer