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.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java Swing | Translucent and shaped Window in Java
- Java Swing | ScrollPaneLayout Class
- Java Swing | JPanel with examples
- Java Swing | Internal Frame with examples
- Java Swing | JMenuBar
- Java Swing | JFileChooser
- Java Swing | Look and Feel
- Java Swing | JTextField
- Java Swing | JProgressBar
- Java Swing | JSpinner
- Java Swing | JPopupMenu
- Java Swing | JTextArea
- JLabel | Java Swing
- Java Swing | JToolBar
- JRadioButton | Java Swing
- Java Swing | ToolTip
- Java Swing | JSlider
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
- Java Swing | Simple Calculator
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.