How to display mask in jtextfield?
1 answer
This will create a hidden text box. When you hit the enter button, what the user entered is displayed. This is using JPasswordField. http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JPasswordField.html
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PasswordField1 extends JApplet implements ActionListener {
/* Declaration */
private JPasswordField Input;
private JTextField Echo;
private Container Panel;
private LayoutManager Layout;
public PasswordField1 () {
/* Instantiation */
Input = new JPasswordField ("", 20);
Layout = new FlowLayout ();
Panel = getContentPane ();
/* Location */
Panel.setLayout (Layout);
Panel.add (Input);
/* Configuration */
Input.addActionListener (this);
}
public void actionPerformed (ActionEvent e) {
char [] Chars;
String Word;
Chars = Input.getPassword();
Word = new String(Chars);
System.out.println("You Entered: " + Word);
}
}
+2
source to share