I have a JSpinner using a SpinnerDateModel which has a start at Jan 1, 2010 00:00:00.000 the end date is Jan 1, 2010 00:12:34.217. I would like my JSpinner.DateEditor to use the format HH:mm:ss.SSS but the spinner doesn't spin with this format. It only spins when "yyyy" is added to the format. How can I get around this?
import java.awt.GridLayout;
import java.util.*;
import javax.swing.*;
public class T extends JPanel {
public T() {
super(new GridLayout(2, 2));
init();
}
private void init() {
Calendar start = GregorianCalendar.getInstance();
Calendar end = GregorianCalendar.getInstance();
start.clear();
end.clear();
start.set(Calendar.YEAR, 2010);
end.set(Calendar.YEAR, 2010);
end.add(Calendar.HOUR_OF_DAY, 12);
SpinnerDateModel m1 =
new SpinnerDateModel(start.getTime(), start.getTime(),
end.getTime(), Calendar.MILLISECOND);
SpinnerDateModel m2 =
new SpinnerDateModel(start.getTime(), start.getTime(),
end.getTime(), Calendar.MILLISECOND);
JSpinner workingSpinner = new JSpinner(m1);
workingSpinner.setEditor(
new JSpinner.DateEditor(workingSpinner,
"yyyy HH:mm:ss.SSS"));
JSpinner notWorkingSpinner = new JSpinner(m2);
notWorkingSpinner.setEditor(
new JSpinner.DateEditor(notWorkingSpinner,
"HH:mm:ss.SSS"));
add(new JLabel("Working"));
add(workingSpinner);
add(new JLabel("!Working"));
add(notWorkingSpinner);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new T());
frame.pack();
frame.setVisible(true);
}
}