Monday, August 4, 2014

JavaFX 8 example: DatePicker


Example code:

package javafx_datepicker;

import java.time.LocalDate;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_DatePicker extends Application {

    @Override
    public void start(Stage primaryStage) {
        DatePicker datePicker = new DatePicker();
        datePicker.setOnAction(new EventHandler() {

            @Override
            public void handle(Event event) {
                LocalDate date = datePicker.getValue();
                System.err.println("Selected date: " + date);
            }

        });

        StackPane root = new StackPane();
        root.getChildren().add(datePicker);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("java-buddy.blogspot.com");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

No comments:

Post a Comment