Search in sources :

Example 1 with PasswordField

use of javafx.scene.control.PasswordField in project jphp by jphp-compiler.

the class UXPasswordField method __construct.

@Override
public void __construct(String text) {
    __wrappedObject = new PasswordField();
    getWrappedObject().setText(text);
}
Also used : PasswordField(javafx.scene.control.PasswordField)

Example 2 with PasswordField

use of javafx.scene.control.PasswordField in project Gargoyle by callakrsos.

the class DialogUtil method showLoginDialog.

/**
	 * login Dialog 로그인 처리 다이얼로그
	 *
	 * @param consumer
	 * @return
	 */
public static <T> Optional<Pair<String, String>> showLoginDialog(Consumer<? super Pair<String, String>> consumer) {
    // Create the custom dialog.
    Dialog<Pair<String, String>> dialog = new Dialog<>();
    dialog.setTitle("Login Dialog");
    dialog.setHeaderText("Look, a Custom Login Dialog");
    dialog.setGraphic(new ImageView(new Image("file:resources/images/login.png")));
    // Set the button types.
    ButtonType loginButtonType = new ButtonType("Login", ButtonData.OK_DONE);
    ButtonType localButtonType = new ButtonType("Local", ButtonData.APPLY);
    dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, localButtonType, ButtonType.CANCEL);
    // 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 username = new TextField();
    username.setPromptText("Username");
    PasswordField password = new PasswordField();
    password.setPromptText("Password");
    grid.add(new Label("Username:"), 0, 0);
    grid.add(username, 1, 0);
    grid.add(new Label("Password:"), 0, 1);
    grid.add(password, 1, 1);
    // Enable/Disable login button depending on whether a username was
    // entered.
    Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
    loginButton.setDisable(true);
    // Do some validation (using the Java 8 lambda syntax).
    username.textProperty().addListener((observable, oldValue, newValue) -> {
        loginButton.setDisable(newValue.trim().isEmpty());
    });
    dialog.getDialogPane().setContent(grid);
    // Request focus on the username field by default.
    Platform.runLater(() -> username.requestFocus());
    // Convert the result to a username-password-pair when the login button
    // is clicked.
    dialog.setResultConverter(dialogButton -> {
        if (dialogButton == loginButtonType) {
            return new Pair<>(username.getText(), password.getText());
        } else if (dialogButton == localButtonType) {
            return new Pair<>(MEMO_LOCAL_USER, "");
        }
        return null;
    });
    Optional<Pair<String, String>> result = dialog.showAndWait();
    result.ifPresent(consumer);
    return result;
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Image(javafx.scene.image.Image) Dialog(javafx.scene.control.Dialog) TextField(javafx.scene.control.TextField) ImageView(javafx.scene.image.ImageView) PasswordField(javafx.scene.control.PasswordField) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair)

Example 3 with PasswordField

use of javafx.scene.control.PasswordField in project sandbox by irof.

the class Login method start.

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("JavaFX Welcome");
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    Text scenetitle = new Text("Welcome");
    scenetitle.setId("welcome-text");
    grid.add(scenetitle, 0, 0, 2, 1);
    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);
    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);
    Label password = new Label("Password:");
    grid.add(password, 0, 2);
    PasswordField passwordField = new PasswordField();
    grid.add(passwordField, 1, 2);
    Button button = new Button("Sign in");
    HBox hBox = new HBox(10);
    hBox.setAlignment(Pos.BOTTOM_RIGHT);
    hBox.getChildren().add(button);
    grid.add(hBox, 1, 4);
    Text actionTarget = new Text();
    actionTarget.setId("actiontarget");
    grid.add(actionTarget, 1, 6);
    button.setOnAction(e -> {
        actionTarget.setText("Sign in button pressed");
    });
    Scene scene = new Scene(grid, 300, 275);
    scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : HBox(javafx.scene.layout.HBox) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) Label(javafx.scene.control.Label) TextField(javafx.scene.control.TextField) Text(javafx.scene.text.Text) PasswordField(javafx.scene.control.PasswordField) Scene(javafx.scene.Scene)

Example 4 with PasswordField

use of javafx.scene.control.PasswordField in project jgnash by ccavanaugh.

the class NetworkAuthenticator method getPasswordAuthentication.

@Override
protected PasswordAuthentication getPasswordAuthentication() {
    final Preferences auth = Preferences.userRoot().node(NODEHTTP);
    final ResourceBundle resources = ResourceUtils.getBundle();
    final char[][] pass = { null };
    final String[] user = new String[1];
    // get the password
    if (auth.get(HTTPPASS, null) != null && !auth.get(HTTPPASS, null).isEmpty()) {
        pass[0] = auth.get(HTTPPASS, null).toCharArray();
    }
    // get the user
    user[0] = auth.get(HTTPUSER, null);
    if (user[0] != null) {
        if (user[0].length() <= 0) {
            user[0] = null;
        }
    }
    // if either returns null, pop a dialog
    if (user[0] == null || pass[0] == null) {
        final Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle(resources.getString("Title.HTTPProxy"));
        dialog.setHeaderText(resources.getString("Message.EnterNetworkAuth"));
        // Set the button types.
        final ButtonType loginButtonType = new ButtonType(resources.getString("Button.Ok"), ButtonBar.ButtonData.OK_DONE);
        ThemeManager.applyStyleSheets(dialog.getDialogPane());
        dialog.getDialogPane().getStyleClass().addAll("dialog");
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
        // Create the username and password labels and fields.
        final GridPane grid = new GridPane();
        grid.getStyleClass().addAll("form");
        final TextField userNameField = new TextField();
        final PasswordField passwordField = new PasswordField();
        grid.add(new Label(resources.getString("Label.UserName")), 0, 0);
        grid.add(userNameField, 1, 0);
        grid.add(new Label(resources.getString("Label.Password")), 0, 1);
        grid.add(passwordField, 1, 1);
        // Enable/Disable login button depending on whether a username was entered.
        final Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        loginButton.setDisable(true);
        // bind the button, must not be empty
        loginButton.disableProperty().bind(userNameField.textProperty().isEmpty());
        dialog.getDialogPane().setContent(grid);
        // Request focus on the username field by default.
        JavaFXUtils.runLater(userNameField::requestFocus);
        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(userNameField.getText(), passwordField.getText());
            }
            return null;
        });
        final Optional<Pair<String, String>> result = dialog.showAndWait();
        result.ifPresent(usernamePassword -> {
            user[0] = usernamePassword.getKey();
            pass[0] = usernamePassword.getValue().toCharArray();
        });
    }
    return new PasswordAuthentication(user[0], pass[0] != null ? pass[0] : new char[0]);
}
Also used : GridPane(javafx.scene.layout.GridPane) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Dialog(javafx.scene.control.Dialog) TextField(javafx.scene.control.TextField) ResourceBundle(java.util.ResourceBundle) PasswordField(javafx.scene.control.PasswordField) Preferences(java.util.prefs.Preferences) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

PasswordField (javafx.scene.control.PasswordField)4 Label (javafx.scene.control.Label)3 TextField (javafx.scene.control.TextField)3 GridPane (javafx.scene.layout.GridPane)3 Insets (javafx.geometry.Insets)2 Node (javafx.scene.Node)2 ButtonType (javafx.scene.control.ButtonType)2 Dialog (javafx.scene.control.Dialog)2 Pair (javafx.util.Pair)2 PasswordAuthentication (java.net.PasswordAuthentication)1 ResourceBundle (java.util.ResourceBundle)1 Preferences (java.util.prefs.Preferences)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 HBox (javafx.scene.layout.HBox)1 Text (javafx.scene.text.Text)1