How to unmask a JavaFX PasswordField or properly mask a TextField?

后端 未结 5 943
孤街浪徒
孤街浪徒 2020-11-29 11:19

In a UI of mine, I have a PasswordField like so (urm the one at the bottom!):

\"Login

5条回答
  •  一整个雨季
    2020-11-29 11:41

    I know this is older, but i was searching for answer and this is my solution:

    @FXML
    private JFXButton showpassword;
    private String password;
    
    showpassword.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
                password = passwordField.getText();
                passwordField.clear();
                passwordField.setPromptText(password);
            });
            showpassword.addEventFilter(MouseEvent.MOUSE_RELEASED, e -> {
                passwordField.setText(password);
                passwordField.setPromptText("Password");
            });
    

    Using button with graphic like "WIN10 Eye - unmask password"

提交回复
热议问题