JavaFX DatePicker Example

In this JavaFX source code example, we will see how to use the JavaFX DatePicker control to select and display date.

DatePicker is a control for choosing a date.

JavaFX DatePicker Example

The example uses a DatePicker control to select and display the date. The date is shown in a label control.

package sample;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage stage) {


    private void initUI(Stage stage) {

        var root = new VBox(15);
        root.setPadding(new Insets(10));

        var lbl = new Label("...");

        var datePicker = new DatePicker();

        datePicker.setOnAction(e -> {

            var date = datePicker.getValue();

        root.getChildren().addAll(datePicker, lbl);

        var scene = new Scene(root, 350, 200);

        stage.setTitle("Date picker");

    public static void main(String[] args) {