我有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);
}
}