views:

2748

answers:

7

Is there any good and free Date AND Time Picker available for Java Swing?

There are a lot date pickers available but no date AND time picker. This is the closest I came across so far: Looking for a date AND time picker

Anybody?

+2  A: 

As you said Date picker is easy, there are many out there.

As for a Time picker, check out how Google Calendar does it when creating a new entry. It allows you to type in anything while at the same time it has a drop down in 30 mins increments. The drop down changes when you change the minutes.

If you need to allow the user to pick seconds, then the best you can do is a typable/drop down combo

Pyrolistical
+1  A: 

For a time picker you can use a JSpinner and set a JSpinner.DateEditor that only shows the time value.

JSpinner timeSpinner = new JSpinner();
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
timeSpinner.setEditor(timeEditor);
timeSpinner.setValue(new Date()); // will only show the current time
Mark
+2  A: 

The best of the best, JCalendar: http://www.toedter.com/en/jcalendar/index.html LGPL licensed.

-100 jcalendar from toedter has no TIMEpicker.
bobndrew
+1  A: 

Use the both combined.. that's what i did:

public static JPanel buildDatePanel(String label, Date value) {
JPanel datePanel = new JPanel();

JDateChooser dateChooser = new JDateChooser();
if (value != null) {
    dateChooser.setDate(value);
}
for (Component comp : dateChooser.getComponents()) {
    if (comp instanceof JTextField) {
 ((JTextField) comp).setColumns(50);
 ((JTextField) comp).setEditable(false);
    }
}

datePanel.add(dateChooser);

SpinnerModel model = new SpinnerDateModel();
JSpinner timeSpinner = new JSpinner(model);
JComponent editor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
timeSpinner.setEditor(editor);
if(value != null) {
    timeSpinner.setValue(value);
}

datePanel.add(timeSpinner);

return datePanel;
}
mya
+1  A: 

What is JDateChooser here ?

Divya
-200 DATE is not the same as TIME.
bobndrew
A: 

if u are using netbeans try http://jdatechooser.sourceforge.net/

Sethunath
The question specifies date AND time chooser, not date only, though. If jdatechooser has a time chooser extension that I don't know of, it would be nice to add details about it.
Gnoupi
A: 

There is the FLib-JCalendar component with a combined Date and Time Picker.

bobndrew