JFormattedTextField to edit TIME only, how?

I need to have in my form a JFormattedTextField to edit *just* the TIME, not datetime or date, only time.How can I do that?
[151 byte] By [Franziska] at [2007-11-27 5:29:40]
# 1

you need only a normal TextField ...

Then you need a SimpleDateFormat-object (java.text.SimpleDateFormat)

create a new object like this

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

then you can call the setText-method of the TextField.

like this

textField.setText(sdf.format(new Date()));

Oleka at 2007-7-12 14:53:04 > top of Java-index,Desktop,Core GUI APIs...
# 2
Ok, thanksBut how about the user typing?I dont just set the time in the text field, I need it be validating when saving and when user types *something* there.
Franziska at 2007-7-12 14:53:04 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hm ... you need a inputfield for users to type a date?

Thats easy too.

Try this :

JSpinner timeSpinner = new JSpinner(new SpinnerDateModel(new Date(), null, null, Calendar.Hour));

timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, "HH:mm' clock'"));

Here you got a JSpinner and it works really good. Try to spin with the different values ...

By the way ... you can edit the SimpleDateFormat-pattern as you like...

Read the api of SimpleDateFormat. So you can easy make your date-style.

Oleka at 2007-7-12 14:53:04 > top of Java-index,Desktop,Core GUI APIs...