Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Dialog<LoginInfo> createLoginDialog() {
- Dialog<LoginInfo> dlg = new Dialog<>();
- dlg.setHeaderText("Please enter login info");
- dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
- GridPane grid = new GridPane();
- grid.setHgap(5);
- grid.setVgap(5);
- grid.add(new Label("Username: "), 0,0);
- grid.add(new Label("Password: "), 0,1);
- TextField uname = new TextField();
- PasswordField pass = new PasswordField();
- grid.add(uname, 1,0);
- grid.add(pass, 1,1);
- // The content may be created using an FXML, of course.
- dlg.getDialogPane().setContent(grid);
- dlg.setResultConverter(buttonType -> {
- if (buttonType == ButtonType.OK)
- return new LoginInfo(uname.getText(), pass.getText());
- else
- return null;
- });
- return dlg;
- }
- public class LoginInfo {
- private final String user;
- private final String password;
- // TODO: Add getters and setters for fields...
- public LoginInfo(String user, String password) {
- this.user = user;
- this.password = password;
- }
- }
- Dialog<LoginInfo> loginDialog = createLoginDialog();
- Optional<LoginInfo> info = loginDialog.showAndWait();
- if (info.isPresent()) {
- // Your login logic here
- } else {
- // Your cancel logic here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement