JFormattedTextField : input time duration value

Posted by bguiz on Stack Overflow See other posts from Stack Overflow or by bguiz
Published on 2010-02-10T05:48:55Z Indexed on 2010/03/16 18:41 UTC
Read the original article Hit count: 473

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

© Stack Overflow or respective owner

Related posts about java

Related posts about jformattedtextfield