我的JSpinner
DateEditor
,HH:mm
看起来像这样:
是否可以同时展示24:00
和00:00
。基本上我希望它像:
23:58,23:59,24:00,00:00,00:01,00:02
而不是
23:58,23:59,00:00,00:01,00:02
我尝试了@Override
getNextValue()
,但似乎我无法解决这个问题。有什么提示吗?
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);
}
}