Year Month Spinner
Posted by Darryl Burke on April 13, 2015
YearMonthSpinner is a composite of two Temporal spinners, one for the month and the other for the year, used to select a java.time.YearMonth. For ease of use, the spinner buttons are located towards the outer edges of the composite component.
The default constructor creates a YearMonthSpinner with the current year and month, with no lower or upper limits; other constructors allow setting an initial year and month, and optionally a lower and/or upper limit.
This code created those two YearMonthSpinners, and the screenshot was captured in 2015:
int thisYear = Year.now().getValue();
YearMonthSpinner fromSpinner = new YearMonthSpinner(YearMonth.of(thisYear, Month.JANUARY));
YearMonthSpinner toSpinner = new YearMonthSpinner(YearMonth.of(thisYear, Month.DECEMBER));
Please note that you will need JDK8 to compile and use this class. You will also need SpinnerTemporalModel and SpinnerTemporalEditor, published earlier.