0

I have a JSpinner with a DateEditor, HH:mm looking like this:

enter image description here

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);
    }
}
Grains
  • 950
  • 3
  • 16
  • 35
  • Because, for me, 00:00 and 24:00 is different days. I.e. if I would like to select only one specific day I need to also give the time for that day 00:00-24:00. Right now I can only say 00:00-23:59 which is not good enought. – Grains Aug 09 '13 at 11:52
  • if i'm not mistaken 24:00 is technically identical in date and time as 00:00 ..... just with different formatting. – pstanton Aug 10 '13 at 01:47

0 Answers0