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 seperately to make it easier to safely change
the ui for the JTextField without affecting password entries.
For the keyboard keys used by this component in the standard Look and
Feel (L&F) renditions, see the
JPasswordField
key assignments.
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. A future release of Swing will provide support for
long term persistence.
JPasswordField()
Constructs a new JPasswordField, with a default document, null starting
text string, and 0 column width.
JPasswordField(Document doc,
String txt,
int columns)
Constructs a new JPasswordField that uses the given text storage
model and the given number of columns.
JPasswordField(int columns)
Constructs a new empty JPasswordField with the specified
number of columns.
JPasswordField(String text)
Constructs a new JPasswordField initialized with the specified text.
JPasswordField(String text,
int columns)
Constructs a new JPasswordField initialized with the specified text
and columns.
Method Summary
void
copy()
Normally transfers the currently selected range in the associated
text model to the system clipboard, leaving the contents
in the text model.
void
cut()
Normally transfers the currently selected range in the associated
text model to the system clipboard, removing the contents
from the model.
boolean
echoCharIsSet()
Returns true if this JPasswordField has a character set for
echoing.
Constructs a new JPasswordField initialized with the specified text
and columns. The document model is set to the default.
Parameters:
text - the text to be displayed, null if none
columns - the number of columns >= 0
JPasswordField
public JPasswordField(Document doc,
String txt,
int columns)
Constructs a new JPasswordField that uses the given text storage
model and the given number of columns. This is the constructor
through which the other constructors feed. The echo character is
set to '*'. If the document model is null, a default one will be
created.
Parameters:
doc - the text storage to use
txt - the text to be displayed, null if none
columns - the 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.
Sets the echo character for this JPasswordField. Note
that this is largely a suggestion to the view as the
view that gets installed can use whatever graphic techniques
it desires to represent the field. Setting a value of 0 unsets
the echo character.
Normally transfers the currently selected range in the associated
text model to the system clipboard, removing the contents
from the model. This is not a good thing for a password field
and is reimplemented to simply beep.
Normally transfers the currently selected range in the associated
text model to the system clipboard, leaving the contents
in the text model. This is not a good thing for a password field
and is reimplemented to simply beep.
Returns the text contained in this TextComponent. If the underlying
document is null, will give a NullPointerException. For stronger
security, it is recommended that the returned character array be
cleared after use by setting each character to zero.
Returns a string representation of this JPasswordField. This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null.
Gets the AccessibleContext associated with this JPasswordField.
For password fields, the AccessibleContext takes the form of an
AccessibleJPasswordField.
A new AccessibleJPasswordField instance is created if necessary.
Submit a bug or feature For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries. Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, California, 94303, U.S.A. All Rights Reserved.