Last active
May 5, 2018 17:55
-
-
Save sharifulislam52/be1124340a9d7f54f7975f2bd9bf2e5e to your computer and use it in GitHub Desktop.
javafx : DatePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.stage.Stage; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
public class Main extends Application { | |
@Override | |
public void start(Stage primaryStage) { | |
try { | |
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml")); | |
Scene scene = new Scene(root,500,300); | |
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.DatePicker?> | |
<?import javafx.scene.control.Label?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<AnchorPane minHeight="300.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController"> | |
<children> | |
<DatePicker fx:id="dp" layoutX="47.0" layoutY="53.0" onAction="#showDate" prefHeight="42.0" prefWidth="187.0" /> | |
<Label fx:id="show_date" layoutX="54.0" layoutY="150.0" prefHeight="42.0" prefWidth="187.0" text="Date" /> | |
</children> | |
</AnchorPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
import javafx.scene.control.DatePicker; | |
import javafx.scene.control.Label; | |
public class MainController { | |
@FXML private DatePicker dp; | |
@FXML private Label show_date; | |
public void showDate(ActionEvent event) { | |
LocalDate ld = dp.getValue(); | |
show_date.setText(ld.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment