JavaFX Tutorial 23 DatePicker Java GUI
Email : [email protected]
Source Code :
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("DatePicker Example ");
DatePicker datePicker = new DatePicker();
Button button = new Button("Read Date");
button.setOnAction(action -?{
LocalDate value = datePicker.getValue();
});
HBox hbox = new HBox(datePicker);
Scene scene = new Scene(hbox, 300, 240);
primaryStage.setScene(scene);
primaryStage.show();
}
Libraries Importing:
import java.time.LocalDate;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
A JavaFX DatePicker control enables the user to enter a date or choose a date from a wizard-like popup dialog. The popup dialog shows only valid dates, so this is an easier way for users to choose a date and ensure that both the date and date format entered in the date picker text field is valid. The JavaFX DatePicker is represented by the class javafx.scene.control.DatePicker .
The DatePicker is a subclass of the ComboBox class, and thus shares some similarities with this class.