Change echo char for JPasswordField in Java
Description
The following code shows how to change echo char for JPasswordField.
Example
import javax.swing.JFrame;
import javax.swing.JPasswordField;
/*w w w .jav a2 s . c om*/
public class Main {
public static void main(String args[]) {
JFrame f = new JFrame("JPasswordField Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPasswordField password = new JPasswordField();
password.setEchoChar('#');
f.add(password);
f.setSize(300, 200);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »