Java Tips Weblog

  • Blog Stats

    • 2,530,130 hits
  • Categories

  • Archives

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 =;
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.

Get The Code

See Also

Swing and Java 8
Temporal Spinners

Related Reading

The Oracle Tutorials: Trail: Date Time
Java API: java.time.YearMonth


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: