Swing JPasswordField

In this tutorial you will learn about the Swing JPasswordField and its application with practical example.

Swing JPasswordField

JPasawordField is a subclass of JTextField . It’s a lightweight single line component which allows users for editing where the view indicates something was typed , but does not show the original character.

JPasswordField Class Declaration

JPasswordField Constructor

Some important and usable constructor summary listed below.

JPasswordField(): This constructor is used to construct a new Password Field.

JPasswordField(Document doc, String text, int columns): This constructor is used to construct a Password Field that uses the given text storage model and the given number of columns.

JPasswordField(int columns): This constructor is used to construct an empty Password Field with specific number of columns.

JPasswordField(String text): This constructor is used to construct a Password field with given string.

JPasswordField(String text, int columns): This constructor is used to construct a Password field with given string and columns.

JPasswordField Method

Some of Useable and important method are listed below.

char[] getPassword(): This method is used to return text of this component.

String getText(): This method is Deprecated , used to get Text of this component.

AccessibleContext getAccessibleContext(): This method returns AccessibleContext which is associated with this JPasswordField.

protected String paramString(): This method returns a string representation of this JTextField.

Example :-

In the below example I have used simple password field so that we can easily understand what does it mean.

Output :-

Just copy this code or run it, you will get your result like above image.

image001

In this tutorial we have learn about the Swing JPasswordField and its application with practical example. I hope you will like this tutorial.