0

In Java Swing, do we have text component that will work just like how we set the time in Microwave.

By default system should display 00:00:00 (hh:mm:ss) in a textfield. Users focus defaults in the far right of the text box in the far right position. For example if user enters 00:00:85, then system should convert that to 01:25, similarly if user enters 00:08:99, then system should convert that to 00:9:39 (9 mins. 39 secs), similarly if user enters 00:03:00, then system should convert that to 00:03:00 (3 Minutes)

Please let me know if we have any component that works just like this or similar to this..

Thanks in Advance..

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1430989
  • 525
  • 2
  • 6
  • 15
  • ... just don't try to do it with a Calendar :) – Marko Topolnik Nov 19 '12 at 20:13
  • 1
    You could have a look at [this](http://stackoverflow.com/questions/11881301/best-way-to-constrain-user-to-enter-a-time-in-a-jtextfield/11881681#11881681) which is a prototype of a time field (it has some issues, but should provide a jumping off point) – MadProgrammer Nov 19 '12 at 22:35

1 Answers1

1

Out of the box, no. You will have to write some custom code.

You could use a JFormattedTextField with a custom format on it. See this post for an example. Only thing you will have to replace is the Format by your own format.

Another possibility is a JSpinner with a custom model where you just loop through a set of fixed values (e.g. incrementing time by 5''). This is how my microwave works. I can just rotate a button which increases the time. I cannot 'type' anything

Community
  • 1
  • 1
Robin
  • 36,233
  • 5
  • 47
  • 99
  • Thank you Robin. I used JSpinner in this case but with slightly different solution to the user. Thank you for your time. – user1430989 Nov 30 '12 at 16:11