JPasswordField is a lightweight component that allows
the editing of a single line of text where the view indicates
something was typed, but does not show the original characters.
You can find further information and examples in
How to Use Text Fields,
a section in The Java Tutorial.
JPasswordField is intended
to be source-compatible with java.awt.TextField
used with echoChar set. It is provided separately
to make it easier to safely change the UI for the
JTextField without affecting password entries.
Note
By default, JPasswordField disables input methods; otherwise, input
characters could be visible while they were composed using input methods.
If an application needs the input methods support, please use the
inherited method, enableInputMethods(true).
Warning
The JPasswordField will not show the
original characters that were typed, instead displaying alternative text or
graphics. However this doesn't prevent the password from appearing in the
system memory. For handling confidential information such as the password
text, refer to the relevant section at
Secure Coding Guidelines.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | JPasswordField.
This class implements accessibility support for the
|
| Modifier and Type | Field and Description |
|---|---|
| private char | |
| private boolean | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | JPasswordField()
Constructs a new |
| public | JPasswordField(String
the text to be displayed, text)null if noneConstructs a new |
| public | JPasswordField(int
the number of columns >= 0 columns)Constructs a new empty |
| public | JPasswordField(String
the text to be displayed, text, int null if nonethe number of columns >= 0 columns)Constructs a new |
| public | JPasswordField(Document
the text storage to use doc, String the text to be displayed, txt, int null if nonethe number of columns to use to calculate
the preferred width >= 0; if columns is set to zero, the
preferred width will be whatever naturally results from
the component implementation columns)Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | copy()
Overrides javax. Invokes |
| pack-priv boolean | customSetUIProperty(String propertyName, Object value)
This method is a hack to get around the fact that we cannot directly override setUIProperty because part of the inheritance hierarchy goes outside of the javax.swing package, and therefore calling a package private method isn't allowed. |
| public void | cut()
Overrides javax. Invokes |
| public boolean | Returns: true if a character is set for echoingReturns true if this |
| public AccessibleContext | Returns: anAccessibleJPasswordField that serves as the
AccessibleContext of this
JPasswordFieldOverrides javax. Implements javax. Returns the |
| public char | |
| public char[] | |
| public String | Returns: the textOverrides javax.
Deprecated
As of Java 2 platform v1.2,
replaced by
getPassword.
Returns the text contained in this |
| public String | Returns: the textthe offset >= 0 offs, int the length >= 0 len)Overrides javax.
Deprecated
As of Java 2 platform v1.2,
replaced by
getPassword.
Fetches a portion of the text represented by the component. |
| public String | Returns: the string "PasswordFieldUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| protected String | Returns: a string representation of thisJPasswordFieldOverrides javax. Returns a string representation of this |
| public void | |
| public void | setText(String t)
Overrides javax. Sets the text of this |
| public void | |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing. |
| echoChar | back to summary |
|---|---|
| private char echoChar | |
| echoCharSet | back to summary |
|---|---|
| private boolean echoCharSet | |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JPasswordField | back to summary |
|---|---|
| public JPasswordField() Constructs a new | |
| JPasswordField | back to summary |
|---|---|
| public JPasswordField(String text) Constructs a new
| |
| JPasswordField | back to summary |
|---|---|
| public JPasswordField(int columns) Constructs a new empty
| |
| JPasswordField | back to summary |
|---|---|
| public JPasswordField(String text, int columns) Constructs a new
| |
| JPasswordField | back to summary |
|---|---|
| public JPasswordField(Document doc, String txt, int columns) Constructs a new | |
| copy | back to summary |
|---|---|
| public void copy() Overrides javax. Invokes | |
| customSetUIProperty | back to summary |
|---|---|
| pack-priv boolean customSetUIProperty(String propertyName, Object value) This method is a hack to get around the fact that we cannot directly override setUIProperty because part of the inheritance hierarchy goes outside of the javax.swing package, and therefore calling a package private method isn't allowed. This method should return true if the property was handled, and false otherwise. | |
| cut | back to summary |
|---|---|
| public void cut() Overrides javax. Invokes | |
| echoCharIsSet | back to summary |
|---|---|
| public boolean echoCharIsSet() Returns true if this
| |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides javax. Implements javax. Returns the
| |
| getEchoChar | back to summary |
|---|---|
| public char getEchoChar() Returns the character to be used for echoing. The default is '*'. The default may be different depending on the currently running Look and Feel. For example, Metal/Ocean's default is a bullet character.
| |
| getPassword | back to summary |
|---|---|
| public char[] getPassword() Returns the text contained in this
| |
| getText | back to summary |
|---|---|
| public String getText() Overrides javax. Deprecated As of Java 2 platform v1.2,
replaced by Returns the text contained in this
For security reasons, this method is deprecated. Use the
| |
| getText | back to summary |
|---|---|
| public String getText(int offs, int len) throws BadLocationException Overrides javax. Deprecated As of Java 2 platform v1.2,
replaced by Fetches a portion of the text represented by the component. Returns an empty string if length is 0.
For security reasons, this method is deprecated. Use the
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| setEchoChar | back to summary |
|---|---|
| public void setEchoChar(char c) Sets the echo character for this
| |
| setText | back to summary |
|---|---|
| public void setText(String t) Overrides javax. Doc from javax. Sets the text of this
Note that text is not a bound property, so no
| |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Doc from javax. Reloads the pluggable UI. The key used to fetch the
new interface is
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing.
| |
JPasswordField class. It provides an implementation of the
Java Accessibility API appropriate to password field user-interface
elements.Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the object (AccessibleRole.PASSWORD_TEXT)Overrides javax. Gets the role of this object. |
| public AccessibleText | Returns: AccessibleText for the JPasswordFieldOverrides javax. Gets the |
| public String | Returns: aString if part and
index are valid.
Otherwise, null is returnedthe part, int CHARACTER, WORD or
SENTENCE to retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| public String | Returns: aString if part and
index are valid.
Otherwise, null is returnedthe part, int CHARACTER, WORD or
SENTENCE to retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| public String | Returns: aString if part and
index are valid.
Otherwise, null is returnedthe part, int CHARACTER, WORD or
SENTENCE to retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| private String | |
| public String | Returns: the text string if the indices are valid. Otherwise,null is returnedthe start index in the text startIndex, int the end index in the text endIndex)Overrides javax. Implements javax. Returns the text between two |
| public AccessibleTextSequence | Returns: anAccessibleTextSequence specifying the text if
part and index are valid. Otherwise,
null is returnedthe part, int CHARACTER, WORD,
SENTENCE, LINE or ATTRIBUTE_RUN to
retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| public AccessibleTextSequence | Returns: anAccessibleTextSequence specifying the text if
part and index are valid. Otherwise,
null is returnedthe part, int CHARACTER, WORD,
SENTENCE, LINE or ATTRIBUTE_RUN to
retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| public AccessibleTextSequence | Returns: anAccessibleTextSequence specifying the text if
part and index are valid. Otherwise,
null is returnedthe part, int CHARACTER, WORD,
SENTENCE, LINE or ATTRIBUTE_RUN to
retrievean index within the text index)Overrides javax. Implements javax. Returns the |
| AccessibleJPasswordField | back to summary |
|---|---|
| protected AccessibleJPasswordField() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Gets the role of this object.
| |
| getAccessibleText | back to summary |
|---|---|
| public AccessibleText getAccessibleText() Overrides javax. Gets the
| |
| getAfterIndex | back to summary |
|---|---|
| public String getAfterIndex(int part, int index) Overrides javax. Implements javax. Returns the
| |
| getAtIndex | back to summary |
|---|---|
| public String getAtIndex(int part, int index) Overrides javax. Implements javax. Returns the
| |
| getBeforeIndex | back to summary |
|---|---|
| public String getBeforeIndex(int part, int index) Overrides javax. Implements javax. Returns the
| |
| getEchoString | back to summary |
|---|---|
| private String getEchoString(String str) | |
| getTextRange | back to summary |
|---|---|
| public String getTextRange(int startIndex, int endIndex) Overrides javax. Implements javax. Returns the text between two
| |
| getTextSequenceAfter | back to summary |
|---|---|
| public AccessibleTextSequence getTextSequenceAfter(int part, int index) Overrides javax. Implements javax. Returns the
| |
| getTextSequenceAt | back to summary |
|---|---|
| public AccessibleTextSequence getTextSequenceAt(int part, int index) Overrides javax. Implements javax. Returns the
| |
| getTextSequenceBefore | back to summary |
|---|---|
| public AccessibleTextSequence getTextSequenceBefore(int part, int index) Overrides javax. Implements javax. Returns the
| |