문제

This is how I created a date JSpinner. When I click on arrows, it can only decrement year by some value (two or one) or increment (only couple of times) by one. I am confused, please help!

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));
도움이 되었습니까?

해결책

Try using y instead of Y

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

Y = Week Year, y = Year

Read: SimpleDateFormat

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top