Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. private Dialog<LoginInfo> createLoginDialog() {
  2. Dialog<LoginInfo> dlg = new Dialog<>();
  3. dlg.setHeaderText("Please enter login info");
  4. dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
  5.  
  6. GridPane grid = new GridPane();
  7. grid.setHgap(5);
  8. grid.setVgap(5);
  9. grid.add(new Label("Username: "), 0,0);
  10. grid.add(new Label("Password: "), 0,1);
  11. TextField uname = new TextField();
  12. PasswordField pass = new PasswordField();
  13. grid.add(uname, 1,0);
  14. grid.add(pass, 1,1);
  15.  
  16. // The content may be created using an FXML, of course.
  17. dlg.getDialogPane().setContent(grid);
  18. dlg.setResultConverter(buttonType -> {
  19. if (buttonType == ButtonType.OK)
  20. return new LoginInfo(uname.getText(), pass.getText());
  21. else
  22. return null;
  23. });
  24. return dlg;
  25. }
  26.  
  27. public class LoginInfo {
  28. private final String user;
  29. private final String password;
  30.  
  31. // TODO: Add getters and setters for fields...
  32.  
  33. public LoginInfo(String user, String password) {
  34. this.user = user;
  35. this.password = password;
  36. }
  37. }
  38.  
  39. Dialog<LoginInfo> loginDialog = createLoginDialog();
  40. Optional<LoginInfo> info = loginDialog.showAndWait();
  41. if (info.isPresent()) {
  42. // Your login logic here
  43. } else {
  44. // Your cancel logic here
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement