Java JSpinner错误地改变了它的年份

时间:2013-08-15 11:23:05

标签: java swing calendar simpledateformat jspinner

这是我创建日期JSpinner的方法。当我点击箭头时,它只能将年份递减一些值(两次或一次)或递增(仅几次)一次。我很困惑,请帮忙!

Date current = calendar.getTime();
SpinnerDateModel yearsData = new SpinnerDateModel(current,null,null,Calendar.YEAR);
JSpinner years = new JSpinner(yearsData);
years.setEditor(new JSpinner.DateEditor(years, "YYYY"));
JFormattedTextField tfYears = ((JSpinner.DefaultEditor)years.getEditor()).getTextField();
tfYears.setHorizontalAlignment(JTextField.RIGHT);
tfYears.setFont(new Font("SansSerif", Font.PLAIN, 10));

1 个答案:

答案 0 :(得分:2)

尝试使用y代替Y

years.setEditor(new JSpinner.DateEditor(years, "yyyy"));

Y =周年,y =年

阅读:SimpleDateFormat