The JPasswordField Class
A JPasswordField is a
text field in which an echo character (* by default) is displayed in place of the
characters typed by the user. This feature is generally used when
entering passwords to avoid showing the password on the screen. Except
for the quirky display, JPasswordField behaves like an ordinary
JTextField, though some steps have
been taken to enhance the password field’s security.
One reason that JPasswordField
is a separate class from JTextField
in Swing (which is not the case in the analogous AWT classes) is so the
L&F can treat them differently by specifying different UI delegates.
The UI delegate is responsible for hiding the input characters in a
JPasswordField.
Properties
Table 19-5 shows
the properties defined by JPasswordField. JPasswordField has its own unique UIClassID value. The value for accessibleContext property is AccessibleJPasswordField, an inner class
that extends the JTextField.AccessibleJTextField class. The
echoChar property specifies the character to be displayed in the
field each time a key is pressed. This character is used to hide the
actual input characters, though the L&F may choose to ignore it
and hide the input characters some other way.
Table 19-5. JPasswordField properties
Property | Data type | get | is | set | Default value |
|---|---|---|---|---|---|
| AccessibleContext | · | AccessibleJPasswordField | ||
| | · | · | '*' | |
password | char[] | · | |||
| string | · | · | ||
| String | · | “PasswordFieldUI” | ||
ooverridden See also properties from the |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access