PasswordField is a part of javax.swing package . The class JPasswordField is a component that allows editing of a single line of text where the view indicates that something was typed by does not show the actual characters. JPasswordField inherits the JTextField class in javax.swing package.
Constructors of the class are :
- JPasswordField(): constructor that creates a new PasswordField
- JPasswordField(int columns) : constructor that creates a new empty PasswordField with specified number of columns.
- JPasswordField(String Password) : constructor that creates a new empty Password field initialized with the given string.
- JPasswordField(String Password, int columns) : constructor that creates a new empty PasswordField with the given string and a specified number of columns .
- JPasswordField(Document doc, String Password, int columns) : constructor that creates a Passwordfield that uses the given text storage model and the given number of columns.
Commonly used method of JPasswordField :
- char getEchoChar() : returns the character used for echoing in JPasswordField.
- setEchoChar(char c) : set the echo character for JPasswordField.
- String getPassword() : returns the text contained in JPasswordField.
- String getText() : returns the text contained in JPasswordField.
1. Program to enter name and password using JTextField and JPasswordField
2. Program to change the echo character of JPasswordField and set initial text for password field
Note : The above programs might not run in an online compiler use an offline IDE.
the default text and number of columns of password can be changed by the programmer as per their need.
- Java Swing | Translucent and shaped Window in Java
- Java Swing | JTable
- JLabel | Java Swing
- Java Swing | JTextArea
- Java Swing | MatteBorder
- Java Swing | ToolTip
- JRadioButton | Java Swing
- Java Swing | JToolBar
- Java Swing | JSlider
- Java Swing | JProgressBar
- Java Swing | JTextField
- Java Swing | JFileChooser
- Java Swing | Look and Feel
- Java Swing | JPopupMenu
- Java Swing | JSpinner
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.