Home » openjdk-7 » javax » swing » [javadoc | source]
javax.swing
public class: JPasswordField [javadoc | source]
java.lang.Object
   java.awt.Component
      java.awt.Container
         javax.swing.JComponent
            javax.swing.text.JTextComponent
               javax.swing.JTextField
                  javax.swing.JPasswordField

All Implemented Interfaces:
    SwingConstants, Scrollable, Accessible, HasGetTransferHandler, Serializable, MenuContainer, ImageObserver

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 java.beans.XMLEncoder .

Nested Class Summary:
protected class  JPasswordField.AccessibleJPasswordField  This class implements accessibility support for the 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 JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}. 

Fields inherited from javax.swing.JTextField:
notifyAction
Fields inherited from javax.swing.text.JTextComponent:
FOCUS_ACCELERATOR_KEY,  DEFAULT_KEYMAP
Fields inherited from javax.swing.JComponent:
DEBUG_GRAPHICS_LOADED,  ui,  listenerList,  paintingChild,  WHEN_FOCUSED,  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,  WHEN_IN_FOCUSED_WINDOW,  UNDEFINED_CONDITION,  TOOL_TIP_TEXT_KEY,  focusController,  accessibleContext
Fields inherited from java.awt.Container:
layoutMgr,  containerListener,  listeningChildren,  listeningBoundsChildren,  descendantsCount,  preserveBackgroundColor,  INCLUDE_SELF,  SEARCH_HEAVYWEIGHTS,  modalComp,  modalAppContext
Fields inherited from java.awt.Component:
peer,  parent,  appContext,  x,  y,  width,  height,  foreground,  background,  font,  peerFont,  cursor,  locale,  bufferStrategy,  ignoreRepaint,  visible,  enabled,  dropTarget,  popups,  focusTraversalKeys,  LOCK,  minSize,  minSizeSet,  prefSize,  prefSizeSet,  maxSize,  maxSizeSet,  componentOrientation,  newEventsOnly,  componentListener,  focusListener,  hierarchyListener,  hierarchyBoundsListener,  keyListener,  mouseListener,  mouseMotionListener,  mouseWheelListener,  inputMethodListener,  windowClosingException,  actionListenerK,  adjustmentListenerK,  componentListenerK,  containerListenerK,  focusListenerK,  itemListenerK,  keyListenerK,  mouseListenerK,  mouseMotionListenerK,  mouseWheelListenerK,  textListenerK,  ownedWindowK,  windowListenerK,  inputMethodListenerK,  hierarchyListenerK,  hierarchyBoundsListenerK,  windowStateListenerK,  windowFocusListenerK,  eventMask,  isInc,  incRate,  TOP_ALIGNMENT,  CENTER_ALIGNMENT,  BOTTOM_ALIGNMENT,  LEFT_ALIGNMENT,  RIGHT_ALIGNMENT,  isPacked,  backgroundEraseDisabled,  eventCache,  accessibleContext
Constructor:
 public 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
 public JPasswordField(int columns) 
 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
 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
Method from javax.swing.JPasswordField Summary:
copy,   customSetUIProperty,   cut,   echoCharIsSet,   getAccessibleContext,   getEchoChar,   getPassword,   getText,   getText,   getUIClassID,   paramString,   setEchoChar,   updateUI
Methods from javax.swing.JTextField:
actionPropertyChanged,   addActionListener,   configurePropertiesFromAction,   createActionPropertyChangeListener,   createDefaultModel,   fireActionPerformed,   getAccessibleContext,   getAction,   getActionListeners,   getActions,   getColumnWidth,   getColumns,   getHorizontalAlignment,   getHorizontalVisibility,   getPreferredSize,   getScrollOffset,   getUIClassID,   hasActionListener,   isValidateRoot,   paramString,   postActionEvent,   removeActionListener,   scrollRectToVisible,   setAction,   setActionCommand,   setColumns,   setDocument,   setFont,   setHorizontalAlignment,   setScrollOffset
Methods from javax.swing.text.JTextComponent:
addCaretListener,   addInputMethodListener,   addKeymap,   composedTextExists,   copy,   cut,   dropLocationForPoint,   fireCaretUpdate,   getAccessibleContext,   getActions,   getCaret,   getCaretColor,   getCaretListeners,   getCaretPosition,   getDisabledTextColor,   getDocument,   getDragEnabled,   getDropLocation,   getDropMode,   getFocusAccelerator,   getFocusedComponent,   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,   restoreComposedText,   saveComposedText,   select,   selectAll,   setCaret,   setCaretColor,   setCaretPosition,   setComponentOrientation,   setDisabledTextColor,   setDocument,   setDragEnabled,   setDropLocation,   setDropMode,   setEditable,   setFocusAccelerator,   setHighlighter,   setKeymap,   setMargin,   setNavigationFilter,   setSelectedTextColor,   setSelectionColor,   setSelectionEnd,   setSelectionStart,   setText,   setUI,   updateInputMap,   updateUI,   viewToModel,   write
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.Container:
add,   add,   add,   add,   add,   addContainerListener,   addImpl,   addNotify,   addPropertyChangeListener,   addPropertyChangeListener,   adjustDecendantsOnParent,   adjustDescendants,   adjustListeningChildren,   applyComponentOrientation,   areFocusTraversalKeysSet,   canContainFocusOwner,   checkGD,   clearCurrentFocusCycleRootOnHide,   clearMostRecentFocusOwnerOnHide,   containsFocus,   countComponents,   countHierarchyMembers,   createChildHierarchyEvents,   createHierarchyEvents,   decreaseComponentCount,   deliverEvent,   dispatchEventImpl,   dispatchEventToSelf,   doLayout,   eventEnabled,   findComponentAt,   findComponentAt,   findComponentAt,   findComponentAtImpl,   getAccessibleAt,   getAccessibleChild,   getAccessibleChildrenCount,   getAlignmentX,   getAlignmentY,   getComponent,   getComponentAt,   getComponentAt,   getComponentCount,   getComponentZOrder,   getComponents,   getComponentsSync,   getComponents_NoClientCode,   getContainerListeners,   getDropTargetEventTarget,   getFocusTraversalKeys,   getFocusTraversalPolicy,   getHeavyweightContainer,   getInsets,   getLayout,   getListeners,   getMaximumSize,   getMinimumSize,   getMouseEventTarget,   getMousePosition,   getOpaqueShape,   getPreferredSize,   getTraversalRoot,   hasHeavyweightDescendants,   hasLightweightDescendants,   increaseComponentCount,   initializeFocusTraversalKeys,   insets,   invalidate,   invalidateParent,   invalidateTree,   isAncestorOf,   isFocusCycleRoot,   isFocusCycleRoot,   isFocusTraversalPolicyProvider,   isFocusTraversalPolicySet,   isRecursivelyVisibleUpToHeavyweightContainer,   isSameOrAncestorOf,   isValidateRoot,   layout,   lightweightPaint,   lightweightPrint,   list,   list,   locate,   minimumSize,   mixOnHiding,   mixOnReshaping,   mixOnShowing,   mixOnValidating,   mixOnZOrderChanging,   numListening,   paint,   paintComponents,   paintHeavyweightComponents,   paramString,   postProcessKeyEvent,   postsOldMouseEvents,   preProcessKeyEvent,   preferredSize,   print,   printComponents,   printHeavyweightComponents,   processContainerEvent,   processEvent,   proxyEnableEvents,   recursiveApplyCurrentShape,   recursiveApplyCurrentShape,   recursiveApplyCurrentShape,   recursiveSubtractAndApplyShape,   recursiveSubtractAndApplyShape,   recursiveSubtractAndApplyShape,   remove,   remove,   removeAll,   removeContainerListener,   removeNotify,   setComponentZOrder,   setFocusCycleRoot,   setFocusTraversalKeys,   setFocusTraversalPolicy,   setFocusTraversalPolicyProvider,   setFont,   setLayout,   transferFocusDownCycle,   update,   updateGraphicsData,   validate,   validateTree,   validateUnconditionally
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
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.JPasswordField Detail:
 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.
 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 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() 
    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() 
    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() 
    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() 
    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() 
    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() 
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 
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() 
    Returns the name of the L&F class that renders this component.
 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.
 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.
 public  void updateUI() 
    {@inheritDoc}