JTextField displays data in plain text. If you need to set the echo content to other characters, you can use the JPasswordField class.
Package com. beyole. util; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JPasswordField; public class test18 {public static void main (String [] args) {JFrame frame = new JFrame ("Crystal "); // instantiate the form object JPasswordField jPasswordField1 = new JPasswordField (); // define the ciphertext box JPasswordField jPasswordField2 = new JPasswordField (); // define the ciphertext box jPasswordField2.setEchoChar ('#'); // set the echo character to # JLabel label1 = new JLabel ("Default ECHO:"); JLabel label2 = new JLabel ("set echo #:"); label1.setBounds (10, 10,100, 20); label2.setBounds (10, 40,100, 20); jPasswordField1.setBounds (110, 10, 80, 20); jPasswordField2.setBounds (110, 40, 50, 20 ); frame. setLayout (null); frame. add (label2); frame. add (label1); frame. add (jPasswordField2); frame. add (jPasswordField1); frame. setSize (300,100); frame. setLocation (300,200); frame. setVisible (true );}}
Program: