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?
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?
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
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
The best of the best, JCalendar: http://www.toedter.com/en/jcalendar/index.html LGPL licensed.
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;
}
There is the FLib-JCalendar component with a combined Date and Time Picker.