所有类


javax.swing
类 JPasswordField

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.text.JTextComponent
                  继承者 javax.swing.JTextField
                      继承者 javax.swing.JPasswordField
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public class JPasswordField
   
   
   
   
   
extends JTextField

JPasswordField 是一个轻量级组件,允许编辑一个单行文本,其视图指示键入内容,但不显示原始字符。有关更多信息和示例,请参阅《The Java Tutorial》中的 How to Use Text Fields 一节。

JPasswordField 与使用 echoChar 设置的 java.awt.TextField 是根本一致的。单独提供它可以较方便地安全更改 JTextField 的 UI 而不影响密码输入。

警告:此类的序列化对象将与以后的 Swing 版本不兼容。当前的序列化支持适用于短期存储或运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder


嵌套类摘要
protected  class JPasswordField.AccessibleJPasswordField
          此类实现对 JPasswordField 类的可访问性支持。
 
从类 javax.swing.JTextField 继承的嵌套类/接口
JTextField.AccessibleJTextField
 
从类 javax.swing.text.JTextComponent 继承的嵌套类/接口
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.JTextField 继承的字段
notifyAction
 
从类 javax.swing.text.JTextComponent 继承的字段
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 javax.swing.SwingConstants 继承的字段
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JPasswordField()
          构造一个新 JPasswordField,使其具有默认文档、为 null 的开始文本字符串和为 0 的列宽度。
JPasswordField(Document doc, String txt, int columns)
          构造一个使用给定文本存储模型和给定列数的新 JPasswordField
JPasswordField(int columns)
          构造一个具有指定列数的新的空 JPasswordField
JPasswordField(String text)
          构造一个利用指定文本初始化的新 JPasswordField
JPasswordField(String text, int columns)
          构造一个利用指定文本和列初始化的新 JPasswordField
 
方法摘要
 void copy()
          对当前外观调用 provideErrorFeedback,这通常启动错误蜂鸣。
 void cut()
          对当前外观调用 provideErrorFeedback,这通常启动错误蜂鸣。
 boolean echoCharIsSet()
          如果此 JPasswordField 具有为回显设置的字符,则返回 true。
 AccessibleContext getAccessibleContext()
          返回与此 JPasswordField 关联的 AccessibleContext
 char getEchoChar()
          返回要用于回显的字符。
 char[] getPassword()
          返回此 TextComponent 中所包含的文本。
 String getText()
          已过时。 从 Java 2 platform v1.2 开始,由 getPassword 来代替。
 String getText(int offs, int len)
          已过时。 从 Java 2 platform v1.2 开始,由 getPassword 来代替。
 String getUIClassID()
          返回呈现此组件的 L&F 类名。
protected  String paramString()
          返回此 JPasswordField 的字符串表示形式。
 void setEchoChar(char c)
          设置此 JPasswordField 的回显字符。
 
从类 javax.swing.JTextField 继承的方法
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, isValidateRoot, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset
 
从类 javax.swing.text.JTextComponent 继承的方法
addCaretListener, addInputMethodListener, addKeymap, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

JPasswordField

public JPasswordField()
构造一个新 JPasswordField,使其具有默认文档、为 null 的开始文本字符串和为 0 的列宽度。


JPasswordField

public JPasswordField(String text)
构造一个利用指定文本初始化的新 JPasswordField。将文档模型设置为默认值,列数为 0。

参数:
text - 要显示的文本;如果没有文本,则为 null

JPasswordField

public JPasswordField(int columns)
构造一个具有指定列数的新的空 JPasswordField。创建一个默认模型,并将其初始字符串设置为 null

参数:
columns - 列数,它 >= 0

JPasswordField

public JPasswordField(String text,
                      int columns)
构造一个利用指定文本和列初始化的新 JPasswordField。将文档模型设置为默认值。

参数:
text - 要显示的文本;如果不存在文本,则为 null
columns - 列数,它 >= 0

JPasswordField

public JPasswordField(Document doc,
                      String txt,
                      int columns)
构造一个使用给定文本存储模型和给定列数的新 JPasswordField。其他构造方法馈通此构造方法。将回显字符设置为 '*'。如果文档模型为 null,则创建默认文档。

参数:
doc - 要使用的文本存储
txt - 要显示的文本;如果不存在文本,则为 null
columns - 用于计算首选宽度的列数,它 >= 0;如果将列数设置为零,则首选宽度将从组件实现自然产生
方法详细信息

getUIClassID

public String getUIClassID()
返回呈现此组件的 L&F 类名。

覆盖:
JTextField 中的 getUIClassID
返回:
字符串 "PasswordFieldUI"
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

getEchoChar

public char getEchoChar()
返回要用于回显的字符。默认值为 '*'。

返回:
回显字符;如果未设置,则返回 0
另请参见:
setEchoChar(char), echoCharIsSet()

setEchoChar

public void setEchoChar(char c)
设置此 JPasswordField 的回显字符。注意,这仅仅是一个建议,因为安装的视图可以使用它所需要的任何图形技术来表示字段。将值设置为 0 指示希望按照键入查看文本,类似于标准 JTextField 的行为。

参数:
c - 要显示的回显字符
另请参见:
echoCharIsSet(), getEchoChar()

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部