Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FXML
- public void showDialogPane() {
- // using Dialog methods
- Dialog<ButtonType> dialog = new Dialog<>();
- // we must set owner which invokes the dialog
- dialog.initOwner(mainBorderPane.getScene().getWindow());
- // setting a header title to dialog pane
- dialog.setHeaderText("Enter your new To Do schedule");
- // setting a window title to dialog
- dialog.setTitle("Add new item");
- // we need to instantiate the FXMLLoader to use it
- FXMLLoader fxmlLoader = new FXMLLoader();
- // setting the FXML file location which will be loaded later
- fxmlLoader.setLocation(getClass().getResource("additemdialog.fxml"));
- try {
- // trying to load the content from FXML file into the dialog pane
- dialog.getDialogPane().setContent(fxmlLoader.load());
- } catch (IOException e ) {
- e.getStackTrace();
- return;
- }
- // creating OK and Cancel button to dialog window
- dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
- dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
- // showing the dialog window and waiting for response by the buttons created above
- Optional<ButtonType> result = dialog.showAndWait();
- if ( result.isPresent() && result.get() == ButtonType.OK) {
- // check for pressing an OK button
- // we must get DialogController instance
- DialogController controller = fxmlLoader.getController();
- // getting the newest ToDo item added in the list
- TodoItem item = controller.processResult();
- // auto-selecting the newest todo item
- todoListView.getSelectionModel().select(item);
- }
- else {
- System.out.println("Cancel is pressed!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement