public class JPasswordField extends JTextField
JPasswordField
是一个轻量级组件,允许编辑单行文本,其中视图指示输入的内容,但不显示原始字符。
你可以找到更多信息和示例How to Use Text Fields ,在Java教程的部分。
JPasswordField
旨在与源兼容java.awt.TextField
用于echoChar
集。 它分开提供,以便更容易地安全地更改JTextField
的UI,而不会影响密码条目。
注意:默认情况下,JPasswordField禁用输入法; 否则,输入字符在使用输入法组合时可以看到。 如果应用程序需要输入法支持,请使用继承的方法, enableInputMethods(true)
。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans
包中。 请参阅XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
protected class |
JPasswordField.AccessibleJPasswordField
这个类实现了可访问性支持
JPasswordField 类。
|
JTextField.AccessibleJTextField
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
notifyAction
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
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 ,用指定的文本和列进行初始化。
|
Modifier and Type | Method and Description |
---|---|
void |
copy()
调用
provideErrorFeedback 当前的外观,通常会发出一个错误提示音。
|
void |
cut()
调用
provideErrorFeedback 当前的外观和感觉,通常会发出一个错误提示音。
|
boolean |
echoCharIsSet()
如果这个
JPasswordField 具有一个用于回
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 的回音
JPasswordField 。
|
void |
updateUI()
重新加载可插拔的UI。
|
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
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, 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, write
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
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
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, 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, transferFocusBackward, transferFocusUpCycle
public JPasswordField()
JPasswordField
,默认文档为
null
起始文本字符串和0列宽。
public JPasswordField(String text)
JPasswordField
,用指定的文本初始化。
文档模型设置为默认值,列数设置为0。
text
- 要显示的文本,如果没有,
null
public JPasswordField(int columns)
JPasswordField
与指定的列数。
创建默认模型,初始字符串设置为null
。
columns
- 列数= 0
public JPasswordField(String text, int columns)
JPasswordField
,用指定的文本和列初始化。
文档模型设置为默认值。
text
- 要显示的文本,如果没有,
null
columns
- 列数> = 0
public String getUIClassID()
getUIClassID
在
JTextField
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
getUIClassID()
。
UI的类型是TextUI
。
invalidate
在设置UI后调用。
public char getEchoChar()
setEchoChar(char)
,
echoCharIsSet()
public void setEchoChar(char c)
JPasswordField
的回波JPasswordField
。
请注意,这主要是一个建议,因为安装的视图可以使用任何图形技术来表示该字段。
设置值为0表示您希望看到类型的文本,类似于标准JTextField
的行为。
c
- 要显示的回显字符
echoCharIsSet()
,
getEchoChar()
public boolean echoCharIsSet()
JPasswordField
具有用于回JPasswordField
的字符集,则返回true。
如果回波字符不为0,则认为该字符被设置。
setEchoChar(char)
,
getEchoChar()
public void cut()
provideErrorFeedback
当前的外观和感觉,通常会发出一个错误提示音。
将相关文本模型中的当前选定范围传输到系统剪贴板以及从模型中删除内容的正常行为对于密码字段是不可接受的。
cut
在
JTextComponent
Toolkit.getSystemClipboard()
, Clipboard
public void copy()
provideErrorFeedback
当前的外观,通常会发出一个错误提示音。
将相关文本模型中的当前选定范围传输到系统剪贴板,并将模型中的内容传送到密码字段是不可接受的。
copy
在
JTextComponent
Toolkit.getSystemClipboard()
, Clipboard
@Deprecated public String getText()
getPassword
。
TextComponent
。
如果底层文件是null
,会给一个NullPointerException
。
出于安全考虑,此方法已被弃用。 请改用* getPassword
方法。
getText
在
JTextComponent
JTextComponent.setText(java.lang.String)
@Deprecated public String getText(int offs, int len) throws BadLocationException
getPassword
取代。
出于安全考虑,此方法已被弃用。 请改用getPassword
方法。
getText
在
JTextComponent
offs
- offset> = 0
len
- 长度> = 0
BadLocationException
- 如果偏移或长度无效
public char[] getPassword()
TextComponent
。
如果底层文件是null
,会给一个NullPointerException
。
为了更强的安全性,建议在使用后将返回的字符数组清除,将每个字符设置为零。
protected String paramString()
JPasswordField
的字符串表示JPasswordField
。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null
。
paramString
在
JTextField
JPasswordField
的字符串表示
JPasswordField
public AccessibleContext getAccessibleContext()
AccessibleContext
与此相关JPasswordField
。
对于密码领域, AccessibleContext
需要一个形式AccessibleJPasswordField
。
如有必要,将创建一个新的AccessibleJPasswordField
实例。
getAccessibleContext
中的
Accessible
getAccessibleContext
在
JTextField
AccessibleJPasswordField
作为
AccessibleContext
这个
JPasswordField
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.