【问题标题】:Java's JSpinner changes it's year wronglyJava JSpinner 错误地更改了年份
【发布时间】:2013-08-15 11:23:04
【问题描述】:

这就是我创建日期 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));

【问题讨论】:

    标签: java swing calendar simpledateformat jspinner


    【解决方案1】:

    尝试使用y 而不是Y

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

    Y = 周年,y = 年

    阅读:SimpleDateFormat

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 2011-07-09
      • 1970-01-01
      • 2021-08-13
      • 2020-09-21
      • 2013-11-15
      • 2020-12-23
      相关资源
      最近更新 更多