Local Date Combo
Posted by Darryl Burke on April 22, 2015
LocalDateCombo is a Swing date picker for selecting a java.time.LocalDate from a drop-down MonthView. As with MonthView, the no-arg constructor creates a LocalDateCombo set to the current date, with no upper or lower limits. Additionally, this uses a default format corresponding to java.time.format.FormatStyle.MEDIUM
Five more constructors allow you to set various combinations of initial / minimum (earliest) / maximum (latest) value, and the display format. Here’s a LocalDateCombo with the MonthView dropped down:
This code created that LocalDateCombo, and the screenshot was captured on 4 April 2015.
new LocalDateCombo(LocalDate.now(),
DateTimeFormatter.ofPattern("E d MMM, uuuu"));
Please note that you will need JDK8 to compile and use this class. You will also need MonthView and related classes, published earlier.
Get The Code
LocalDateCombo.java
MonthView.java
YearMonthSpinner.java
SpinnerTemporalModel.java
SpinnerTemporalEditor.java
See Also
Swing and Java 8
Month View
Year Month Spinner
Temporal Spinners
Related Reading
The Oracle Tutorials: Trail: Date Time
Java API: java.time.LocalDate
Java API: java.time.format.DateTimeFormatter
Java API: java.time.format.FormatStyle
Java API: javax.swing.JComboBox
Leave a Reply