Java jPasswordField – Kensoft PH https://kensoftph.com Power up your knowledge in programming Wed, 21 Sep 2022 10:07:54 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://kensoftph.com/wp-content/uploads/2021/07/cropped-Kensoftph-New-logo-32x32.png Java jPasswordField – Kensoft PH https://kensoftph.com 32 32 JPasswordField in Java Hide or Show Password | 100% best for beginners https://kensoftph.com/jpasswordfield-in-java-show-or-hide-password/ https://kensoftph.com/jpasswordfield-in-java-show-or-hide-password/#comments Fri, 02 Apr 2021 08:11:00 +0000 https://kensoftph.com/hide-and-show-password-in-jpasswordfield/ jPasswordField in Java

jPasswordField in java is part of the javax.swing package. jPasswordField is a component that allows the user to input a password that does not show the actual letter or character inputted in the password field.

Java jPasswordField Show or Hide Password

Well, to show the actual characters inputted in the password field in Java. You will need the setEchoChar() method to actually see it.

  • getEchoChar() – Returns the character to be used for echoing.

  • setEchoChar() – Sets the echo character for this JPasswordField.

Example

password.setEchoChar('*');
password.getEchoChar();

jPasswordField in Java

The output here will be * asterisk because we have set the EchoChar to *. So, showing the actual characters will be this. See the example code below.

Another Example

if(jToggleButton1.isSelected()){
    pass.setEchoChar((char)0); //By this line of code. We will actually see the actual characters
    jToggleButton1.setText("Hide");
}else{
    pass.setEchoChar('u25cf');
    jToggleButton1.setText("Show");
}

Java jPasswordField

When the JToggleButton is selected, the actual characters will show. If you hide the characters, the setEchoChar(‘u25cf’); is going to handle it. the output of the u25cf will be the black circle dot.

Output

JPasswordField in Java

 

 

YouTube Video

]]>
https://kensoftph.com/jpasswordfield-in-java-show-or-hide-password/feed/ 1 Java Tutorial: hide and show password in Java swing jPasswordField nonadult