Java - GUI - Date time input box

J

jc_usernet

Hello.
Just a quick question. Where can I find a good library class that
performs the operation of allowing me to easily input a date and time
on a GUI (with other swing components)?
I expected to find this in the swing / Java native presentation;

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

Regards JC.....
 
M

markspace

jc_usernet said:
I expected to find this in the swing / Java native presentation;


You would be correct.


new JFormattedTextField( new SimpleDateFormat( "mm/dd/yyyy" ) );

and

Calandar now = Calendar.getInstance();
Calandar earliestDate = ...
Calendar latestDate = ...
SpinnerModel model = new SpinnerDateModel( now.getTime(),
earliestDate.getTime(), latestDate.getTime(), Calendar.WEEK_OF_YEAR );
JSpinner spinner = new JSpinner( model );


In general, the Java docs are your friend. However, it can be difficult
to find a class if you don't know what to look for. I used Learning
Java by O'Reilly, 3rd ed., to look these up. Learning Java is a good
reference to keep around, and it does seem to cover the most important
classes, and give examples of their use, which I've copied partially for
you above.
 
J

John B. Matthews

jc_usernet said:
Hello.
Just a quick question. Where can I find a good library class that
performs the operation of allowing me to easily input a date and time
on a GUI (with other swing components)?
I expected to find this in the swing / Java native presentation;

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

In addition to the date spinner suggested by markspace, here's an
example of using Input verifier to accommodate multiple formats:

<http://groups.google.com/group/comp.lang.java.programmer/msg/d9f7a7702139b48f>
 
M

markspace

John said:
In addition to the date spinner suggested by markspace, here's an
example of using Input verifier to accommodate multiple formats:


Just in case I wasn't very clear, I gave two solutions:

1. Use JFormattedTextField with SimpleDateFormat.
2. Use JSpinner.


I guess the "and" in the middle of that wasn't too indicative of a
change in thought.
 
J

John B. Matthews

markspace said:
Just in case I wasn't very clear, I gave two solutions:

1. Use JFormattedTextField with SimpleDateFormat.
2. Use JSpinner.


I guess the "and" in the middle of that wasn't too indicative of a
change in thought.

No, I read your response carelessly. On reflection, I see
SimpleDateFormat as foundational to both spinner and verifier.
I think you are right to emphasize it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top