Hide/Show Password in a JTextFIeld (Java Swing)

后端 未结 3 1683
日久生厌
日久生厌 2021-02-05 10:35

So I\'ve been working on a Password Strength Checker and the way it works is that the user enters some random text into a textfield and then instantaneous visual feedback (break

相关标签:
3条回答
  • 2021-02-05 10:37

    ok thanks for tutorialnya,

    and ex,

    action chechbox / double click

    private void lihatActionPerformed(java.awt.event.ActionEvent evt) {  
    
       if (lihat.isSelected()) {
          password.setEchoChar((char)0); //password = JPasswordField
       } else {
          password.setEchoChar('*');
       }
    }
    
    0 讨论(0)
  • 2021-02-05 10:40

    Use Password Field Instead of using textfield

    0 讨论(0)
  • 2021-02-05 10:49

    How exactly do I mask the user input with asterisks preserving its original value?

    Use the JPasswordField which has nice function jPasswordField.getPassword(); to get the password as char[] to work with.

    • Use jPasswordField1.setEchoChar('*') to mask the password characters with *.
    • If you wish to see the value you are inserting use jPasswordField1.setEchoChar((char)0); Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.

    Tutorial and Reference:

    1. How to use Password Fields
    2. setEchoChar(char)
    0 讨论(0)
提交回复
热议问题