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
Constructor: |
public JPasswordField() {
this(null,null,0);
}
Constructs a new JPasswordField ,
with a default document, null starting
text string, and 0 column width. |
public JPasswordField(String text) {
this(null, text, 0);
}
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
|
public JPasswordField(int columns) {
this(null, null, 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
|
public JPasswordField(String text,
int columns) {
this(null, text, 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
|
public JPasswordField(Document doc,
String txt,
int columns) {
super(doc, txt, columns);
// We could either leave this on, which wouldn't be secure,
// or obscure the composted text, which essentially makes displaying
// it useless. Therefore, we turn off input methods.
enableInputMethods(false);
}
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
|
Methods from javax.swing.JComponent: |
---|
_paintImmediately, addAncestorListener, addNotify, addVetoableChangeListener, alwaysOnTop, checkIfChildObscuredBySibling, clientPropertyChanged, compWriteObjectNotify, componentInputMapChanged, computeVisibleRect, computeVisibleRect, contains, createToolTip, disable, dndDone, dropLocationForPoint, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getGraphicsInvoked, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPainting, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintForceDoubleBuffered, paintImmediately, paintImmediately, paintToOffscreen, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, safelyGetGraphics, safelyGetGraphics, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setDropLocation, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setUIProperty, setVerifyInputWhenFocusTarget, setVisible, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update, updateUI |
Methods from java.awt.Component: |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, adjustListeningChildrenOnParent, applyComponentOrientation, applyCompoundShape, applyCurrentShape, areBoundsValid, areFocusTraversalKeysSet, areInputMethodsEnabled, autoProcessMouseWheel, bounds, canBeFocusOwner, canBeFocusOwnerRecursively, checkGD, checkImage, checkImage, checkTreeLock, checkWindowClosingException, clearCurrentFocusCycleRootOnHide, clearMostRecentFocusOwnerOnHide, coalesceEvents, constructComponentName, contains, contains, containsFocus, countHierarchyMembers, createBufferStrategy, createBufferStrategy, createHierarchyEvents, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, dispatchMouseWheelToAncestor, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, eventTypeEnabled, findUnderMouseInWindow, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessControlContext, getAccessibleContext, getAccessibleIndexInParent, getAccessibleStateSet, getAlignmentX, getAlignmentY, getBackBuffer, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getBoundsOp, getBufferStrategy, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getContainer, getContainingWindow, getCursor, getCursor_NoClientCode, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFocusTraversalKeys_NoIDCheck, getFont, getFontMetrics, getFont_NoClientCode, getForeground, getGraphics, getGraphicsConfiguration, getGraphicsConfiguration_NoClientCode, getGraphics_NoClientCode, getHWPeerAboveMe, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getLocationOnScreen_NoTreeLock, getLocationOnWindow, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getNativeContainer, getNextFocusCandidate, getNormalShape, getObjectLock, getOpaqueShape, getParent, getParent_NoClientCode, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSiblingIndexAbove, getSiblingIndexBelow, getSize, getSize, getToolkit, getToolkitImpl, getTraversalRoot, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initializeFocusTraversalKeys, inside, invalidate, invalidateIfValid, invalidateParent, isAutoFocusTransferOnDisposal, isBackgroundSet, isCoalescingEnabled, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusTraversableOverridden, isFocusable, isFontSet, isForegroundSet, isInstanceOf, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isMixingNeeded, isNonOpaqueForMixing, isOpaque, isPreferredSizeSet, isRecursivelyVisible, isSameOrAncestorOf, isShowing, isValid, isVisible, isVisible_NoClientCode, keyDown, keyUp, layout, lightweightPaint, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mixOnHiding, mixOnReshaping, mixOnShowing, mixOnValidating, mixOnZOrderChanging, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, numListening, paint, paintAll, paintHeavyweightComponents, paramString, pointRelativeToComponent, postEvent, postsOldMouseEvents, preferredSize, prepareImage, prepareImage, print, printAll, printHeavyweightComponents, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, relocateComponent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusHelper, requestFocusHelper, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setAutoFocusTransferOnDisposal, setBackground, setBounds, setBounds, setBoundsOp, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusTraversalKeys_NoIDCheck, setFocusable, setFont, setForeground, setGraphicsConfiguration, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setRequestFocusController, setSize, setSize, setVisible, show, show, size, subtractAndApplyShape, subtractAndApplyShapeBelowMe, toString, transferFocus, transferFocus, transferFocusBackward, transferFocusBackward, transferFocusUpCycle, update, updateCursorImmediately, updateGraphicsData, updateZOrder, validate |
Method from javax.swing.JPasswordField Detail: |
public void copy() {
if (getClientProperty("JPasswordField.cutCopyAllowed") != Boolean.TRUE) {
UIManager.getLookAndFeel().provideErrorFeedback(this);
} else {
super.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. |
boolean customSetUIProperty(String propertyName,
Object value) {
if (propertyName == "echoChar") {
if (!echoCharSet) {
setEchoChar((Character)value);
echoCharSet = false;
}
return true;
}
return false;
}
This method is a hack to get around the fact that we cannot
directly override setUIProperty because part of the inheritance heirarchy
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. |
public void cut() {
if (getClientProperty("JPasswordField.cutCopyAllowed") != Boolean.TRUE) {
UIManager.getLookAndFeel().provideErrorFeedback(this);
} else {
super.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. |
public boolean echoCharIsSet() {
return echoChar != 0;
}
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. |
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJPasswordField();
}
return accessibleContext;
}
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. |
public char getEchoChar() {
return echoChar;
}
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. |
public char[] getPassword() {
Document doc = getDocument();
Segment txt = new Segment();
try {
doc.getText(0, doc.getLength(), txt); // use the non-String API
} catch (BadLocationException e) {
return null;
}
char[] retValue = new char[txt.count];
System.arraycopy(txt.array, txt.offset, retValue, 0, txt.count);
return retValue;
}
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. |
public String getText() {
return super.getText();
} Deprecated! As - of Java 2 platform v1.2,
replaced by getPassword .
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. |
public String getText(int offs,
int len) throws BadLocationException {
return super.getText(offs, len);
} Deprecated! As - of Java 2 platform v1.2,
replaced by getPassword .
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. |
public String getUIClassID() {
return uiClassID;
}
Returns the name of the L&F class that renders this component. |
protected String paramString() {
return super.paramString() +
",echoChar=" + echoChar;
}
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 . |
public void setEchoChar(char c) {
echoChar = c;
echoCharSet = true;
repaint();
revalidate();
}
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 . |
public void updateUI() {
if(!echoCharSet) {
echoChar = '*';
}
super.updateUI();
}
|