- 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:
-
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
是一个轻量级组件,允许编辑单行文本,其中视图表示已打字,但不显示原始字符。 您可以在“Java教程”一节中的 How to Use Text Fields中找到更多信息和示例。JPasswordField
旨在是源兼容java.awt.TextField
与用于echoChar
集。 它分开提供,以便更容易地安全地更改JTextField
的UI,而不会影响密码条目。注意:默认情况下,JPasswordField禁用输入法; 否则,输入字符在使用输入法组合时可以看到。 如果应用程序需要输入法支持,请使用继承的方法,
enableInputMethods(true)
。警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4版本开始,所有JavaBeans的长期存储支持已被添加到
java.beans
软件包中。 请参阅XMLEncoder
。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 protected class
JPasswordField.AccessibleJPasswordField
该类实现JPasswordField
类的可访问性支持。-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
-
Nested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextField
-
-
Field Summary
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
-
Fields inherited from class javax.swing.JTextField
notifyAction
-
Fields inherited from 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
-
-
构造方法摘要
构造方法 Constructor 描述 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
,它使用给定的文本存储模型和给定的列数。
-
方法摘要
所有方法 接口方法 具体的方法 弃用的方法 Modifier and Type 方法 描述 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。-
Methods inherited from class 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from class 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
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, 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, hide, 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, 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
-
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, fireCaretUpdate, 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, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, viewToModel, viewToModel2D, write
-
Methods inherited from class 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
-
-
-
-
构造方法详细信息
-
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()
。 UI的类型是TextUI
。invalidate
在设置UI后调用。
-
getEchoChar
public char getEchoChar()
返回要用于回显的字符。 默认值为'*'。 根据当前运行的外观和感觉,默认值可能会有所不同。 例如,Metal / Ocean的默认值是一个子弹字符。- 结果
- 回波字符,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()
已过时。 从Java 2平台v1.2开始,由getPassword
代替。返回此TextComponent
包含的文本。 如果基础文件是null
,将给出一个NullPointerException
。出于安全考虑,此方法已被弃用。 请改用
* getPassword
方法。- 重写:
-
getText
在JTextComponent
- 结果
- 文本
- 另请参见:
-
JTextComponent.setText(java.lang.String)
-
getText
@Deprecated public String getText(int offs, int len) throws BadLocationException
已过时。 从Java 2平台v1.2开始,由getPassword
替代。获取由组件表示的文本的一部分。 如果长度为0,则返回一个空字符串。出于安全考虑,此方法已被弃用。 请改用
getPassword
方法。- 重写:
-
getText
在JTextComponent
- 参数
-
offs
- offset> = 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
-
-