JEP draft: JEP: Add a JDatePicker UI Component to the Swing UI Toolkit (Preview)

OwnerTejesh R
TypeFeature
ScopeSE
StatusSubmitted
Componentclient-libs / javax.swing
Discussionclient dash libs dash dev at openjdk dot org
EffortM
DurationM
Reviewed byKevin Rushforth, Philip Race, Prasanta Sadhukhan
Created2025/09/29 13:55
Updated2026/01/09 05:44
Issue8368874

Summary

Add to the Swing UI toolkit a JDatePicker component which has an intuitive UI, an easy-to-use API and supports a wide range of common use cases, such as picking a single day or range of days from a month calendar.

This is a Preview API (see https://openjdk.org/jeps/12)

Goals

Non-Goals

Motivation

Description

The proposal is to add new public APIs under the javax.swing package hierarchy in the java.desktop module. These APIs will provide a JDatePicker UI component which allows a user to select a date from a calendar view.

The core components of the JDatePicker are:

The Date Picker is designed to be either embedded in a container or to be used via a popup dialog API. A user selected date from the calendar view is copied to the textfield provided by Date Picker, and vice versa. Both are initialized with an initial value, which is either set by the application or by a default date which is the current date. The calendar view is always a month view and supports display of year, month, weeks, and days of the week. Forward and backward navigation buttons provide navigation through Month or Year. Current Month or Year can be selected using an appropriate panel which will open up when clicking on the Month or Year Label.

The Calendar view is application extensible and customizable, using a provided AbstractCalendarPanel .

A DateSelectionModel interface is provided which defines methods for handling selection of a date or dates and also supports event listeners to be notified when a date is selected.

JDatePicker provides a BasicCalendarPanelUI class for date selection.

JDatePicker provides APIs to

Sample code references:

Set single selection mode and get a date:

JDatePicker datePicker = new JDatePicker();
 datePicker.getCalendarPanel().getDateSelectionModel().addChangeListener(e -> {
       LocalDate date = datePicker.getDate();
       System.out.println("Selected date : " + date);
 });

Set range selection mode and get range of date(start and end range):

JDatePicker datePicker = new JDatePicker();
 datePicker.setDateSelectionMode(DateSelectionModel.SelectionMode.RANGE_SELECTION); 
 datePicker.getCalendarPanel().getDateSelectionModel().addChangeListener(e ->  {
        SortedSet<LocalDate> dates = datePicker.getDates();
        System.out.println("Start date : " + dates.getFirst());
        System.out.println("End date : " + dates.getLast());
 });

Set initial date through API:

JDatePicker datePicker = new JDatePicker();
datePicker.getCalendarPanel().setDate(LocalDate.of(2025, Calendar.JULY + 1, 25));

Set year selection scroll limit to 200 years before current year and 200 years after current year:

JDatePicker datePicker = new JDatePicker();
datePicker.getCalendarPanel().setYearSelectionLimit(200);

Set text field formatter:

JDatePicker datePicker = new JDatePicker();
datePicker.setTextFieldFormatter(DateTimeFormatter.ISO_WEEK_DATE);

UI references:

Alternatives

Testing

New tests will be created to test this new Swing component, these tests include but are not limited to:

As a demonstration, SwingSet2 will be enhanced to have a Date Picker tab.