Example usage for javafx.scene.control PasswordField setPromptText

List of usage examples for javafx.scene.control PasswordField setPromptText

Introduction

In this page you can find the example usage for javafx.scene.control PasswordField setPromptText.

Prototype

public final void setPromptText(String value) 

Source Link

Usage

From source file:Main.java

private static Node createLoginPanel() {
    final ToggleGroup toggleGroup = new ToggleGroup();

    final TextField textField = new TextField();
    textField.setPrefColumnCount(10);//  w  ww  .j av a2 s.  c  om
    textField.setPromptText("Your name");

    final PasswordField passwordField = new PasswordField();
    passwordField.setPrefColumnCount(10);
    passwordField.setPromptText("Your password");

    final ChoiceBox<String> choiceBox = new ChoiceBox<String>(FXCollections.observableArrayList("English",
            "\u0420\u0443\u0441\u0441\u043a\u0438\u0439", "Fran\u00E7ais"));
    choiceBox.setTooltip(new Tooltip("Your language"));
    choiceBox.getSelectionModel().select(0);

    final HBox panel = createHBox(6, createVBox(2, createRadioButton("High", toggleGroup, true),
            createRadioButton("Medium", toggleGroup, false), createRadioButton("Low", toggleGroup, false)),
            createVBox(2, textField, passwordField), choiceBox);
    panel.setAlignment(Pos.BOTTOM_LEFT);
    configureBorder(panel);

    return panel;
}

From source file:Main.java

License:asdf

@Override
public void start(Stage primaryStage) {
    User user = new User();
    Group root = new Group();
    Scene scene = new Scene(root, 320, 100);
    primaryStage.setScene(scene);//from  ww  w.  j  a v  a  2s .  c  o m

    Text userName = new Text();
    userName.textProperty().bind(user.userNameProperty());

    PasswordField passwordField = new PasswordField();
    passwordField.setPromptText("Password");
    user.passwordProperty().bind(passwordField.textProperty());

    // user hits the enter key
    passwordField.setOnAction(actionEvent -> {
        if (accessGranted.get()) {
            System.out.println("granted access:" + user.getUserName());
            System.out.println("password:" + user.getPassword());
            Platform.exit();
        } else {
            primaryStage.setTitle("no access");
        }
    });

    passwordField.textProperty().addListener((obs, ov, nv) -> {
        boolean granted = passwordField.getText().equals(MY_PASS);
        accessGranted.set(granted);
        if (granted) {
            primaryStage.setTitle("");
        }
    });
    VBox formLayout = new VBox(4);
    formLayout.getChildren().addAll(userName, passwordField);
    formLayout.setLayoutX(12);
    formLayout.setLayoutY(12);

    root.getChildren().addAll(formLayout);
    primaryStage.show();
}

From source file:de.perdoctus.ebikeconnect.gui.dialogs.LoginDialog.java

@PostConstruct
public void init() {
    final ImageView graphic = new ImageView(
            new Image(getClass().getResource("/app-icon.png").toExternalForm()));
    graphic.setPreserveRatio(true);//from   www . j av  a2  s.  co  m
    graphic.setFitHeight(64);
    setGraphic(graphic);
    setResizable(true);
    setWidth(400);
    setResizable(false);

    setTitle(rb.getString("dialogTitle"));
    setHeaderText(rb.getString("dialogMessage"));

    final ButtonType loginButtonType = new ButtonType(rb.getString("loginButton"),
            ButtonBar.ButtonData.OK_DONE);
    getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 10, 10, 10));
    grid.setPrefWidth(getWidth());
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.NEVER, HPos.LEFT, true));
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.ALWAYS, HPos.LEFT, true));

    final String rbUsername = rb.getString(CFG_USERNAME);
    final TextField txtUsername = new TextField();
    txtUsername.setPromptText(rbUsername);
    txtUsername.setText(config.getString(CFG_USERNAME, ""));

    final Label lblUsername = new Label(rbUsername);
    lblUsername.setLabelFor(txtUsername);
    grid.add(lblUsername, 0, 0);
    grid.add(txtUsername, 1, 0);

    final String rbPassword = rb.getString(CFG_PASSWORD);
    final PasswordField txtPassword = new PasswordField();
    txtPassword.setPromptText(rbPassword);
    if (config.getBoolean(CFG_SAVE_PASSWORD, false)) {
        txtPassword.setText(config.getString(CFG_PASSWORD, ""));
    }

    final Label lblPassword = new Label(rbPassword);
    lblPassword.setLabelFor(txtPassword);
    grid.add(lblPassword, 0, 1);
    grid.add(txtPassword, 1, 1);

    final CheckBox cbSavePassword = new CheckBox(rb.getString("save-password"));
    cbSavePassword.setSelected(config.getBoolean(CFG_SAVE_PASSWORD, false));
    grid.add(cbSavePassword, 1, 2);

    getDialogPane().setContent(grid);

    // Enable/Disable login button depending on whether a username was entered.
    final Node loginButton = getDialogPane().lookupButton(loginButtonType);
    loginButton.disableProperty()
            .bind(txtUsername.textProperty().isEmpty().or(txtPassword.textProperty().isEmpty()));

    setResultConverter(buttonType -> {
        if (buttonType == loginButtonType) {
            config.setProperty(CFG_USERNAME, txtUsername.getText());
            config.setProperty(CFG_SAVE_PASSWORD, cbSavePassword.isSelected());
            if (cbSavePassword.isSelected()) {
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
            } else {
                config.clearProperty(CFG_PASSWORD);
            }
            return new Credentials(txtUsername.getText(), txtPassword.getText());
        } else {
            return null;
        }
    });

    if (txtUsername.getText().isEmpty()) {
        txtUsername.requestFocus();
    } else {
        txtPassword.requestFocus();
        txtPassword.selectAll();
    }
}

From source file:User.java

private HBox drawRow2() {
    PasswordField passwordField = new PasswordField();
    passwordField.setFont(Font.font("SanSerif", 20));
    passwordField.setPromptText("Password");
    passwordField.setStyle(/*w w w.java2 s.  c  o  m*/
            "-fx-text-fill:black; " + "-fx-prompt-text-fill:gray; " + "-fx-highlight-text-fill:black; "
                    + "-fx-highlight-fill: gray; " + "-fx-background-color: rgba(255, 255, 255, .80); ");

    passwordField.prefWidthProperty().bind(primaryStage.widthProperty().subtract(55));
    user.passwordProperty().bind(passwordField.textProperty());

    // error icon
    SVGPath deniedIcon = new SVGPath();
    deniedIcon.setFill(Color.rgb(255, 0, 0, .9));
    deniedIcon.setStroke(Color.WHITE);//
    deniedIcon.setContent("M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 "
            + "16.447,13.08710.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10"
            + ".946,24.248 16.447,18.746 21.948,24.248z");
    deniedIcon.setVisible(false);

    SVGPath grantedIcon = new SVGPath();
    grantedIcon.setFill(Color.rgb(0, 255, 0, .9));
    grantedIcon.setStroke(Color.WHITE);//
    grantedIcon.setContent(
            "M2.379,14.729 5.208,11.899 12.958,19.648 25.877," + "6.733 28.707,9.56112.958,25.308z");
    grantedIcon.setVisible(false);

    //
    StackPane accessIndicator = new StackPane();
    accessIndicator.getChildren().addAll(deniedIcon, grantedIcon);
    accessIndicator.setAlignment(Pos.CENTER_RIGHT);

    grantedIcon.visibleProperty().bind(GRANTED_ACCESS);

    // user hits the enter key
    passwordField.setOnAction(actionEvent -> {
        if (GRANTED_ACCESS.get()) {
            System.out.printf("User %s is granted access.\n", user.getUserName());
            System.out.printf("User %s entered the password: %s\n", user.getUserName(), user.getPassword());
            Platform.exit();
        } else {
            deniedIcon.setVisible(true);
        }

        ATTEMPTS.set(ATTEMPTS.add(1).get());
        System.out.println("Attempts: " + ATTEMPTS.get());
    });

    // listener when the user types into the password field
    passwordField.textProperty().addListener((obs, ov, nv) -> {
        boolean granted = passwordField.getText().equals(MY_PASS);
        GRANTED_ACCESS.set(granted);
        if (granted) {
            deniedIcon.setVisible(false);
        }
    });

    // listener on number of attempts
    ATTEMPTS.addListener((obs, ov, nv) -> {
        if (MAX_ATTEMPTS == nv.intValue()) {
            // failed attempts
            System.out.printf("User %s is denied access.\n", user.getUserName());
            Platform.exit();
        }
    });

    // second row
    HBox row2 = new HBox(3);
    row2.getChildren().addAll(passwordField, accessIndicator);

    return row2;
}