Hi guys,
I am trying to create a JSpinner with the following format HH:MM but it is not working. The spinner keeps displaying both the date and the time. Can somebody tell me what's wrong with my code? I would really appreciate it ...
////////////////////////////////////////////////////////////////////////
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test {
public static void main(String[] args) {
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.add(new TimeSpinner(), BorderLayout.WEST);
f.add(new TimeSpinner(), BorderLayout.EAST);
f.setVisible(true);
f.pack();
}
}
class TimeSpinner extends JSpinner {
public TimeSpinner() {
super();
// spinner date model
SpinnerDateModel sdm = new SpinnerDateModel();
sdm.setCalendarField(Calendar.MINUTE);
this.setModel(sdm);
try {
this.commitEdit();
} catch (Exception e) {
e.printStackTrace();
}
JSpinner.DateEditor de = (JSpinner.DateEditor)this.getEditor();
de.getFormat().applyPattern("hh:mm a"
;
}
}
I am trying to create a JSpinner with the following format HH:MM but it is not working. The spinner keeps displaying both the date and the time. Can somebody tell me what's wrong with my code? I would really appreciate it ...
////////////////////////////////////////////////////////////////////////
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test {
public static void main(String[] args) {
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.add(new TimeSpinner(), BorderLayout.WEST);
f.add(new TimeSpinner(), BorderLayout.EAST);
f.setVisible(true);
f.pack();
}
}
class TimeSpinner extends JSpinner {
public TimeSpinner() {
super();
// spinner date model
SpinnerDateModel sdm = new SpinnerDateModel();
sdm.setCalendarField(Calendar.MINUTE);
this.setModel(sdm);
try {
this.commitEdit();
} catch (Exception e) {
e.printStackTrace();
}
JSpinner.DateEditor de = (JSpinner.DateEditor)this.getEditor();
de.getFormat().applyPattern("hh:mm a"
}
}