Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do {
- // Create the custom dialog.
- Dialog<Pair<String, String>> dialog = new Dialog<>();
- dialog.setTitle("Login Dialog");
- dialog.setHeaderText("Look, a Custom Login Dialog");
- //Set the button types.
- ButtonType dalejButtonType = new ButtonType("Dalej", ButtonBar.ButtonData.OK_DONE);
- ButtonType cancelButton = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
- dialog.getDialogPane().getButtonTypes().addAll(dalejButtonType, cancelButton);
- // Create the username and password labels and fields.
- GridPane grid = new GridPane();
- grid.setHgap(10);
- grid.setVgap(10);
- grid.setPadding(new Insets(20, 150, 10, 10));
- TextField imie = new TextField();
- imie.setPromptText("Imię");
- TextField email = new TextField();
- email.setPromptText("eMail");
- grid.add(new Label("Imię:"), 0, 0);
- grid.add(imie, 1, 0);
- grid.add(new Label("eMail:"), 0, 1);
- grid.add(email, 1, 1);
- // Enable/Disable login button depending on whether a username was entered.
- Node loginButton = dialog.getDialogPane().lookupButton(dalejButtonType);
- loginButton.setDisable(true);
- // Do some validation (using the Java 8 lambda syntax).
- imie.textProperty().addListener((observable, oldValue, newValue) -> {
- loginButton.setDisable(newValue.trim().isEmpty());
- });
- dialog.getDialogPane().setContent(grid);
- // Request focus on the username field by default.
- Platform.runLater(() -> imie.requestFocus());
- // Convert the result to a username-password-pair when the login button is clicked.
- dialog.setResultConverter(dialogButton -> {
- if (dialogButton == dalejButtonType) {
- return new Pair<>(imie.getText(), email.getText());
- }
- if (dialogButton == cancelButton) {
- return new Pair<>(imie.getText(), email.getText());
- }
- return null;
- });
- Optional<Pair<String, String>> result = dialog.showAndWait();
- result.ifPresent(usernamePassword -> {
- System.out.println("Username=" + usernamePassword.getKey() + ", Password=" + usernamePassword.getValue());
- } while(flag);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement