I have a JSpinner
with a DateEditor
, HH:mm
looking like this:
Is it possible to make this show both 24:00
and 00:00
. Basically I would like it to go like:
23:58, 23:59, 24:00, 00:00, 00:01, 00:02
instead of
23:58, 23:59, 00:00, 00:01, 00:02
I made a try to @Override
the getNextValue()
but it seems like I cant fix this problem in there. Any tips?
public class SpinnerMain {
public static void main(String[] args) {
JSpinner s = new JSpinner(new SpinnerDateModel() {
boolean show24 = true;
@Override
public Object getNextValue() {
Calendar cal = Calendar.getInstance();
cal.setTime(getDate());
int field = getCalendarField();
// If the Spinner should show "24"
int min = cal.get(Calendar.MINUTE);
if (min == 0 && field == Calendar.MINUTE && show24) {
show24 = false;
// Change the display value ....
}
cal.add(field, 1);
Date next = cal.getTime();
return ((getEnd() == null) || (getEnd().compareTo(next) >= 0)) ? next
: null;
}
});
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(s, "HH:mm");
s.setEditor(timeEditor);
Date d = new Date();
d.setTime(1000 * (22 * 3600) + 1000 * 59 * 60);
s.setValue(d);
JFrame frame = new JFrame();
frame.add(s);
frame.pack();
frame.setVisible(true);
}
}