- 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
@JavaBean(description="Allows the editing of a line of text but doesn\'t show the characters.") public class JPasswordField extends JTextField
JPasswordField
是一个轻量级组件,允许编辑单行文本,其中视图指示键入的内容,但不显示原始字符。 您可以在How to Use Text Fields ( The Java Tutorial中的一节)中找到更多信息和示例。JPasswordField
旨在与echoChar
设置的java.awt.TextField
源兼容。 它是单独提供的,可以更轻松地安全地更改JTextField
的UI,而不会影响密码输入。注意:默认情况下,JPasswordField禁用输入方法; 否则,输入字符在使用输入法编写时可以显示。 如果应用程序需要输入方法支持,请使用继承的方法
enableInputMethods(true)
。警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans
软件包中添加了对所有JavaBeansjava.beans
长期存储的支持。 请参阅XMLEncoder
。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected class
JPasswordField.AccessibleJPasswordField
此类实现JPasswordField
类的可访问性支持。-
嵌套类/接口声明在类 javax.swing.JTextField
JTextField.AccessibleJTextField
-
嵌套类/接口声明在类 javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
-
嵌套类/接口声明在类 javax.swing.JComponent
JComponent.AccessibleJComponent
-
嵌套类/接口声明在类 java.awt.Container
Container.AccessibleAWTContainer
-
-
字段汇总
-
声明的属性在类 javax.swing.JTextField
notifyAction
-
声明的属性在类 javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
-
声明的属性在类 javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
声明的属性在类 java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields declared in interface 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
-
-
构造方法摘要
构造方法 构造器 描述 JPasswordField()
构造一个新的JPasswordField
,其默认文档为null
起始文本字符串为0列宽。JPasswordField(int columns)
构造具有指定列数的新空JPasswordField
。JPasswordField(String text)
构造一个使用指定文本初始化的新JPasswordField
。JPasswordField(String text, int columns)
构造一个使用指定文本和列初始化的新JPasswordField
。JPasswordField(Document doc, String txt, int columns)
构造一个新的JPasswordField
,它使用给定的文本存储模型和给定的列数。
-
方法摘要
所有方法 实例方法 具体的方法 弃用的方法 变量和类型 方法 描述 void
copy()
在当前外观上调用provideErrorFeedback
,这通常会发出错误蜂鸣声。void
cut()
在当前外观上调用provideErrorFeedback
,这通常会发出错误蜂鸣声。boolean
echoCharIsSet()
如果此JPasswordField
具有用于回显的字符集,则返回true。AccessibleContext
getAccessibleContext()
返回与AccessibleContext
相关联的JPasswordField
。char
getEchoChar()
返回用于回显的字符。char[]
getPassword()
返回此TextComponent
包含的文本。String
getText()
已过时。截至Java 2平台v1.2,由getPassword
取代。String
getText(int offs, int len)
已过时。截至Java 2平台v1.2,由getPassword
取代。String
getUIClassID()
返回呈现此组件的L&F类的名称。protected String
paramString()
返回此JPasswordField
的字符串表示JPasswordField
。void
setEchoChar(char c)
设置此JPasswordField
的回显字符。void
updateUI()
重新加载可插入的UI。-
声明方法的类 javax.swing.JTextField
actionPropertyChanged, 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, addKeymap, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, viewToModel, viewToModel2D, write
-
声明方法的类 javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, 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, transferFocusDownCycle, validate, validateTree
-
声明方法的类 java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
构造方法详细信息
-
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
-
-
方法详细信息
-
getUIClassID
@BeanProperty(bound=false) public String getUIClassID()
返回呈现此组件的L&F类的名称。- 重写:
-
getUIClassID
,类JTextField
- 结果
- 字符串“PasswordFieldUI”
- 另请参见:
-
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
updateUI
public void updateUI()
重新加载可插入的UI。 用于获取新接口的密钥是getUIClassID()
。 用户界面的类型是TextUI
。 设置UI后调用invalidate
。- 重写:
-
updateUI
,类JTextComponent
- 从以下版本开始:
- 1.6
- 另请参见:
-
JComponent.setUI(javax.swing.plaf.ComponentUI)
,UIManager.getLookAndFeel()
,UIManager.getUI(javax.swing.JComponent)
-
getEchoChar
public char getEchoChar()
返回用于回显的字符。 默认值为“*”。 默认值可能会有所不同,具体取决于当前运行的外观。 例如,Metal / Ocean的默认值是项目符号。- 结果
- echo字符,如果未设置则为0
- 另请参见:
-
setEchoChar(char)
,echoCharIsSet()
-
setEchoChar
@BeanProperty(bound=false, visualUpdate=true, description="character to display in place of the real characters") public void setEchoChar(char c)
设置此JPasswordField
的回显字符。 请注意,这在很大程度上是一个建议,因为安装的视图可以使用它希望表示该字段的任何图形技术。 将值设置为0表示您希望在键入文本时看到该文本,类似于标准JTextField
的行为。- 参数
-
c
- 要显示的回显字符 - 另请参见:
-
echoCharIsSet()
,getEchoChar()
-
echoCharIsSet
public boolean echoCharIsSet()
如果此JPasswordField
具有用于回显的字符集,则返回true。 如果回声字符不为0,则认为设置了字符。- 结果
- 如果为回显设置了字符,则为true
- 另请参见:
-
setEchoChar(char)
,getEchoChar()
-
cut
public void cut()
在当前外观上调用provideErrorFeedback
,这通常会发出错误蜂鸣声。 将关联文本模型中当前所选范围传输到系统剪贴板并从模型中删除内容的正常行为对于密码字段是不可接受的。- 重写:
-
cut
在类JTextComponent
- 另请参见:
-
Toolkit.getSystemClipboard()
,Clipboard
-
copy
public void copy()
在当前外观上调用provideErrorFeedback
,这通常会发出错误蜂鸣声。 将关联文本模型中当前选定范围传输到系统剪贴板并从模型中保留内容的正常行为对于密码字段是不可接受的。- 重写:
-
copy
类JTextComponent
- 另请参见:
-
Toolkit.getSystemClipboard()
,Clipboard
-
getText
@Deprecated public String getText()
Deprecated.As of Java 2 platform v1.2, replaced bygetPassword
.返回此TextComponent
包含的文本。 如果基础文件是null
,则会给出NullPointerException
。出于安全原因,不推荐使用此方法。 请改用
* getPassword
方法。- 重写:
-
getText
类JTextComponent
- 结果
- 文本
- 另请参见:
-
JTextComponent.setText(java.lang.String)
-
getText
@Deprecated public String getText(int offs, int len) throws BadLocationException
Deprecated.As of Java 2 platform v1.2, replaced bygetPassword
.获取组件表示的部分文本。 如果length为0,则返回空字符串。出于安全原因,不推荐使用此方法。 请改用
getPassword
方法。- 重写:
-
getText
在类JTextComponent
- 参数
-
offs
- 偏移量> = 0 -
len
- 长度> = 0 - 结果
- 文本
- 异常
-
BadLocationException
- 如果偏移量或长度无效
-
getPassword
@BeanProperty(bound=false) public char[] getPassword()
返回此TextComponent
包含的文本。 如果基础文件是null
,则会给出NullPointerException
。 为了提高安全性,建议在使用后通过将每个字符设置为零来清除返回的字符数组。- 结果
- 文本
-
paramString
protected String paramString()
返回此JPasswordField
的字符串表示JPasswordField
。 此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null
。- 重写:
-
paramString
在类JTextField
- 结果
-
此
JPasswordField
的字符串表示JPasswordField
-
getAccessibleContext
@BeanProperty(bound=false) public AccessibleContext getAccessibleContext()
返回与AccessibleContext
相关联的JPasswordField
。 对于密码字段,该AccessibleContext
需要一个形式AccessibleJPasswordField
。 如有必要,将创建一个新的AccessibleJPasswordField
实例。- Specified by:
-
getAccessibleContext
,界面Accessible
- 重写:
-
getAccessibleContext
在类JTextField
- 结果
-
AccessibleJPasswordField
,作为AccessibleContext
的JPasswordField
-
-