Java Swing - I have a requirement to convert enter number to minutes and seconds in HH:MM format [closed]

StackOverflow https://stackoverflow.com/questions/13461378

Question

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..

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top