by Dinesh Thakur Category: Swing

The PasswordField is a special kind of textfield. It is a single line textfield used for accepting passwords without displaying the characters typed in. Each typed character is represented by an echo character typically an astriek (*). To create a PasswordField component, instantiate the JpasswordField class.

import javax.swing.*;

import java.awt.* ;
class JPasswordFieldExample extends JFrame
{
     JPasswordFieldExample()
    {
        setLayout(new FlowLayout());
        JLabel lblUserid = new JLabel("Userid");
        JTextField txtUserid = new JTextField("Mr Thakur",15);
        JLabel lblpassword = new JLabel("password");
        JPasswordField txtpassword = new JPasswordField(15);
        add(lblUserid); add(txtUserid);
        add(lblpassword); add(txtpassword);
    }
}
 class JPasswordFieldJavaExample
 {
       public static void main(String args[])
      { 
           JPasswordFieldExample frame = new JPasswordFieldExample();
           frame.setTitle("JPasswordField in Java Swing Example");
           frame.setBounds(200,250,250,150);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
     }
}

JPasswordField in Java Swing Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article