©
本文档使用
php中文网手册 发布
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
javax.swing.JPasswordField
public class JPasswordField
JPasswordField 是一个轻量级组件,允许编辑单行文本,其视图指示键入内容,但不显示原始字符。有关更多信息和示例,请参阅 The Java Tutorial 中的 How to Use Text Fields 一节。
JPasswordField 与使用 echoChar 设置的 java.awt.TextField 是根本一致的。单独提供它可以较方便地安全更改 JTextField 的 UI 而不影响密码输入。
注:
默认情况下,JPasswordField 禁用输入法;否则,当使用输入法组合时,输入字符应该是可见的。如果应用程序需要输入法支持,请使用继承方法 enableInputMethods(true)。
警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy。
警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
| 嵌套类摘要 | |
|---|---|
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 |
| 从类 java.awt.Component 继承的嵌套类/接口 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, 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 的回显字符。 |
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, 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, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, viewToModel, write |
| 从类 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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 |
| 构造方法详细信息 |
|---|
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 - 要显示的文本;如果不存在文本,则为 nullcolumns - 列数,它 >= 0
public JPasswordField(Document doc,
String txt,
int columns)
JPasswordField。其他构造方法馈通此构造方法。将回显字符设置为 '*',但可以通过当前外观更改。如果文档模型为 null,则创建默认文档。
doc - 要使用的文本存储txt - 要显示的文本;如果不存在文本,则为 nullcolumns - 用于计算首选宽度的列数,它 >= 0;如果将列数设置为 0,则首选宽度将从组件实现自然产生| 方法详细信息 |
|---|
public String getUIClassID()
JTextField 中的 getUIClassID
JComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
getUIClassID()。该 UI 的类型是 TextUI。设置该 UI 之后调用 invalidate。
JTextComponent 中的 updateUI
JComponent.setUI(javax.swing.plaf.ComponentUI),
UIManager.getLookAndFeel(),
UIManager.getUI(javax.swing.JComponent)
public char getEchoChar()
setEchoChar(char),
echoCharIsSet()
public void setEchoChar(char c)
JPasswordField 的回显字符。注意,这仅仅是一个建议,因为安装的视图可以使用它所需要的任何图形技术来表示字段。将值设置为 0 指示希望按照键入查看文本,类似于标准 JTextField 的行为。
c - 要显示的回显字符echoCharIsSet(),
getEchoChar()
public boolean echoCharIsSet()
JPasswordField 具有为回显设置的字符,则返回 true。如果回显字符不为 0,则考虑设置字符。
setEchoChar(char),
getEchoChar()
public void cut()
provideErrorFeedback,这通常启动错误蜂鸣。将关联模型中的当前选定范围传输到系统剪贴板并从模型中移除内容,这种普通行为对于密码字段而言,是不可接受的。
JTextComponent 中的 cut
Toolkit.getSystemClipboard(),
Clipboard
public void copy()
provideErrorFeedback,这通常启动错误蜂鸣。将关联模型中的当前选定范围传输到系统剪贴板并在模型中保留内容,这种普通行为对于密码字段而言,是不可接受的。
JTextComponent 中的 copy
Toolkit.getSystemClipboard(),
Clipboard
@Deprecated public String getText()
getPassword 来代替。
TextComponent 中所包含的文本。如果基础文档为 null,则将给出 NullPointerException。
出于安全考虑,此方法已废弃。使用 getPassword 方法来代替。
JTextComponent 中的 getText
JTextComponent.setText(java.lang.String)
@Deprecated
public String getText(int offs,
int len)
throws BadLocationException
getPassword 来代替。
出于安全考虑,此方法已废弃。使用 getPassword 方法来代替。
JTextComponent 中的 getText
offs - 偏移量,它 >= 0len - 长度,它 >= 0
BadLocationException - 如果偏移量或长度无效public char[] getPassword()
TextComponent 中所包含的文本。如果基础文档为 null,则将给出 NullPointerException。为了取得较高的安全性,建议将每个字符设置为 0 以便在使用后清除返回的字符数组。
protected String paramString()
JPasswordField 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null。
JTextField 中的 paramString
JPasswordField 的字符串表示形式public AccessibleContext getAccessibleContext()
JPasswordField 关联的 AccessibleContext。对于密码字段,AccessibleContext 采用 AccessibleJPasswordField 的形式。必要时要创建新的 AccessibleJPasswordField 实例。
Accessible 中的 getAccessibleContext
JTextField 中的 getAccessibleContext
AccessibleJPasswordField,它充当此 JPasswordField 的 AccessibleContext
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。