Java Tips Weblog

  • Blog Stats

    • 2,530,124 hits
  • Categories

  • Archives

Month View

Posted by Darryl Burke on April 2, 2015

MonthView is a composite of a YearMonthSpinner and a tabular calendar display of the selected month.  The table can be navigated with the arrow keys, and the month can be changed by the mouse scroll wheel. Optionally, a link for setting the value to the current date can be displayed.  Clicking on a displayed date sets it as the selected value.

The no-arg constructor creates a MonthView set to the current date, with no upper or lower bounds, and without a link for the current date.  Other constructors allow setting these values.  Here’s a MonthView set to 7 April 2015 that prevents selection of any date after 20 April 2015:

MonthView

This code created that MonthView, and the screenshot was captured on 3 April 2015.

new MonthView(LocalDate.of(2015, Month.APRIL, 7),
      null,
      LocalDate.of(2015, Month.APRIL, 20),
      true);

Please note that you will need JDK8 to compile and use this class.  You will also need YearMonthSpinner and related classes, published earlier.

Get The Code

MonthView.java
YearMonthSpinner.java
SpinnerTemporalModel.java
SpinnerTemporalEditor.java

See Also

Swing and Java 8
Year Month Spinner
Temporal Spinners

Related Reading

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

Advertisement

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

 
%d bloggers like this: