Using JPasswordField : JPasswordField « Swing « Java Tutorial






Using JPasswordField
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class JPasswordFieldTest extends JFrame {

  public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("JTextField Test");
    frame.setLayout(new GridLayout(2, 2));
    JLabel label = new JLabel("User Name:", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT);
    JTextField userNameField = new JTextField(20);
    JPasswordField passwordField = new JPasswordField();
    frame.add(label);
    frame.add(userNameField);
    frame.add(label2);
    frame.add(passwordField);
    frame.setSize(200, 70);
    frame.setVisible(true);
  }
}








14.17.JPasswordField
14.17.1.Using JPasswordFieldUsing JPasswordField
14.17.2.Password field with key eventPassword field with key event
14.17.3.Add action listener to JPasswordField
14.17.4.Using Actions with Text Components: JPasswordField
14.17.5.Customizing a JPasswordField Look and Feel