This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
javax.swing
class JPasswordField
- All Implemented Interfaces:
- MenuContainer, ImageObserver, Serializable, Accessible, Scrollable, SwingConstants, TransferHandler.HasGetTransferHandler
-
Most common way to construct:
-
JPasswordField password = new JPasswordField(20);
Based on 31 examples
public class JPasswordField
extends JTextField
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: 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 JavaBeansTM
has been added to the java.beans
package.
Please see {@link java.beans.XMLEncoder}.
Nested Class Summary |
protected class |
This class implements accessibility support for the
JPasswordField class. |
Constructor Summary |
Constructs a new JPasswordField ,
with a default document, null starting
text string, and 0 column width.
|
Constructs a new JPasswordField that uses the
given text storage model and the given number of columns.
|
Constructs a new empty JPasswordField with the specified
number of columns.
|
Constructs a new JPasswordField initialized
with the specified text.
|
Constructs a new JPasswordField initialized with
the specified text and columns.
|
Method Summary |
void |
Invokes provideErrorFeedback on the current
look and feel, which typically initiates an error beep.
|
void |
Invokes provideErrorFeedback on the current
look and feel, which typically initiates an error beep.
|
boolean |
Returns true if this JPasswordField has a character
set for echoing.
|
AccessibleContext |
Returns the AccessibleContext associated with this
JPasswordField .
|
char |
Returns the character to be used for echoing.
|
char[] |
Returns the text contained in this TextComponent .
|
String |
Returns the text contained in this TextComponent .
|
String |
Fetches a portion of the text represented by the
component.
|
String |
Returns the name of the L&F class that renders this component.
|
protected String |
Returns a string representation of this JPasswordField .
|
void |
Sets the echo character for this JPasswordField .
|
void |
Reloads the pluggable UI.
|
Methods inherited from class javax.swing.JTextField |
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset |
Methods inherited from class javax.swing.text.JTextComponent |
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getAccessibleContext, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paramString, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JPasswordField
public JPasswordField()
-
Constructs a new
JPasswordField
,
with a default document, null
starting
text string, and 0 column width.
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 '*', but may be changed by the current
Look and Feel. 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
JPasswordField
public JPasswordField(int columns)
-
Constructs a new empty
JPasswordField
with the specified
number of columns. A default model is created, and the initial string
is set to null
.
- Parameters:
columns
- the number of columns >= 0
JPasswordField
public JPasswordField(String text)
-
Constructs a new
JPasswordField
initialized
with the specified text. The document model is set to the
default, and the number of columns to 0.
- Parameters:
text
- the text to be displayed, null
if none
JPasswordField
public JPasswordField(String text,
int columns)
-
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
copy
public void copy()
-
Invokes
provideErrorFeedback
on the current
look and feel, which typically initiates an error beep.
The normal behavior of transferring the
currently selected range in the associated text model
to the system clipboard, and leaving the contents from
the model, is not acceptable for a password field.
- Overrides:
copy
in class JTextComponent
cut
public void cut()
-
Invokes
provideErrorFeedback
on the current
look and feel, which typically initiates an error beep.
The normal behavior of transferring the
currently selected range in the associated text model
to the system clipboard, and removing the contents from
the model, is not acceptable for a password field.
- Overrides:
cut
in class JTextComponent
echoCharIsSet
public boolean echoCharIsSet()
-
Returns true if this
JPasswordField
has a character
set for echoing. A character is considered to be set if the echo
character is not 0.
- Returns:
- true if a character is set for echoing
getAccessibleContext
public AccessibleContext getAccessibleContext()
-
Returns 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.
- Overrides:
getAccessibleContext
in class JTextField
- Returns:
- an
AccessibleJPasswordField
that serves as the
AccessibleContext
of this
JPasswordField
getEchoChar
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.
- Returns:
- the echo character, 0 if unset
getPassword
public char[] getPassword()
-
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:
- the text
getText
public String getText()
-
Returns the text contained in this
TextComponent
.
If the underlying document is null
, will give a
NullPointerException
.
For security reasons, this method is deprecated. Use the
* getPassword
method instead.
- Overrides:
getText
in class JTextComponent
- Returns:
- the text
getText
public String getText(int offs,
int len)
throws BadLocationException
-
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
getPassword
method instead.
- Overrides:
getText
in class JTextComponent
- Parameters:
offs
- the offset >= 0
len
- the length >= 0
- Returns:
- the text
- Throws:
BadLocationException
- if the offset or length are invalid
getUIClassID
public String getUIClassID()
-
Returns the name of the L&F class that renders this component.
- Overrides:
getUIClassID
in class JTextField
- Returns:
- the string "PasswordFieldUI"
paramString
protected String paramString()
-
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
.
- Overrides:
paramString
in class JTextField
- Returns:
- a string representation of this
JPasswordField
setEchoChar
public void setEchoChar(char c)
-
Sets the echo character for this
JPasswordField
.
Note that this is largely a suggestion, since the
view that gets installed can use whatever graphic techniques
it desires to represent the field. Setting a value of 0 indicates
that you wish to see the text as it is typed, similar to
the behavior of a standard JTextField
.
- Parameters:
c
- the echo character to display
updateUI
public void updateUI()
-
{@inheritDoc}
- Overrides:
updateUI
in class JTextComponent
This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
This page displays the
Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
The official Sun™ documentation can be found here at
http://java.sun.com/javase/6/docs/api/.