JavaTM Platform
Standard Ed. 6

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 は、1 行のテキストの編集を可能にする、軽量コンポーネントです。 ただし、ビューは入力があったことを示しますが、どの文字が入力されたかは表示しません。詳細や使用例については、「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 に適しています。JDK Version 1.4 以降、すべての JavaBeans の長期間の運用サポートは、java.beans パッケージに追加されています。詳細は、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 を構築します。
JPasswordField(Document doc, String txt, int columns)
          指定されたテキストストレージモデルと列数を使用して新規の JPasswordField を構築します。
JPasswordField(int columns)
          指定された列数で新規の空の JPasswordField を構築します。
JPasswordField(String text)
          指定されたテキストで初期化される新規 JPasswordField を構築します。
JPasswordField(String text, int columns)
          指定されたテキストと列で初期化される新規 JPasswordField を構築します。
 
メソッドの概要
 void copy()
          現在の Look & Feel で provideErrorFeedback を呼び出します。
 void cut()
          現在の Look & Feel で provideErrorFeedback を呼び出します。
 boolean echoCharIsSet()
          エコー表示に使用する文字セットが JPasswordField に用意されている場合に true を返します。
 AccessibleContext getAccessibleContext()
          この JPasswordField に関連した AccessibleContext を返します。
 char getEchoChar()
          エコーに使用する文字を返します。
 char[] getPassword()
          この TextComponent に格納されたテキストを返します。
 String getText()
          推奨されていません。 Java 2 プラットフォーム 1.2 以降、getPassword に置き換えられました。
 String getText(int offs, int len)
          推奨されていません。 Java 2 プラットフォーム 1.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
 

コンストラクタの詳細

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 を構築します。これは、ほかのコンストラクタが入力するコンストラクタです。エコー文字はアスタリスク (*) に設定されていますが、現在の Look & Feel を使って変更可能です。ドキュメントモデルが null の場合はデフォルトモデルが作成されます。

パラメータ:
doc - 使用するテキストストレージ
txt - 表示されるテキスト。ない場合は null
columns - 適切な幅の計算に使用する列数。 0 以上。列数を 0 に設定すると、 適切な幅はコンポーネントの実装から自然に得られる 値になる
メソッドの詳細

getUIClassID

public String getUIClassID()
このコンポーネントを描画する L&F クラスの名前を返します。

オーバーライド:
クラス JTextField 内の getUIClassID
戻り値:
文字列「PasswordFieldUI」
関連項目:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
プラグイン可能な UI を再ロードします。新しいインタフェースを取得するのに使うキーは getUIClassID() です。UI のタイプは TextUI です。 invalidate は、UI の設定後に呼び出されます。

オーバーライド:
クラス JTextComponent 内の updateUI
導入されたバージョン:
1.6
関連項目:
JComponent.setUI(javax.swing.plaf.ComponentUI), UIManager.getLookAndFeel(), UIManager.getUI(javax.swing.JComponent)

getEchoChar

public char getEchoChar()
エコーに使用する文字を返します。デフォルトは「*」です。デフォルトは現在実行中の Look & Feel によって異なる可能性があります。たとえば、Metal/Ocean のデフォルトは箇条書きシンボルです。

戻り値:
エコー文字。設定がない場合は 0
関連項目:
setEchoChar(char), echoCharIsSet()

setEchoChar

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()
現在の Look & Feel で provideErrorFeedback を呼び出します。 通常これは、エラービープ音を開始します。関連したテキストモデル内の現在選択されている領域をシステムクリップボードに転送して、モデルからコンテンツを削除する通常の動作は、パスワードの入力フィールドには受け入れられません。

オーバーライド:
クラス JTextComponent 内の cut
関連項目:
Toolkit.getSystemClipboard(), Clipboard

copy

public void copy()
現在の Look & Feel で provideErrorFeedback を呼び出します。 通常これは、エラービープ音を開始します。関連したテキストモデル内の現在選択されている領域をシステムクリップボードに転送して、モデルにコンテンツを残す通常の動作は、パスワードの入力フィールドには受け入れられません。

オーバーライド:
クラス JTextComponent 内の copy
関連項目:
Toolkit.getSystemClipboard(), Clipboard

getText

@Deprecated
public String getText()
推奨されていません。 Java 2 プラットフォーム 1.2 以降、getPassword に置き換えられました。

この TextComponent に格納されたテキストを返します。基本となるドキュメントが null の場合は、NullPointerException を返します。  

セキュリティー上の理由から、このメソッドは推奨されません。代わりに * getPassword メソッドを使用してください。

オーバーライド:
クラス JTextComponent 内の getText
戻り値:
テキスト
関連項目:
JTextComponent.setText(java.lang.String)

getText

@Deprecated
public String getText(int offs,
                                 int len)
               throws BadLocationException
推奨されていません。 Java 2 プラットフォーム 1.2 以降、getPassword に置き換えられました。

コンポーネントが表すテキストの一部を取り出します。長さが 0 の場合は、空の文字列を返します。

セキュリティー上の理由から、このメソッドは推奨されません。代わりに getPassword メソッドを使用してください。

オーバーライド:
クラス JTextComponent 内の getText
パラメータ:
offs - オフセット >= 0
len - 長さ >= 0
戻り値:
テキスト
例外:
BadLocationException - オフセットまたは長さが無効な場合

getPassword

public char[] getPassword()
この TextComponent に格納されたテキストを返します。基本となるドキュメントが null の場合は、NullPointerException を返します。セキュリティー強化のために、返された文字の配列を使用したあとは、各文字をゼロに設定してクリアすることをお勧めします。

戻り値:
テキスト

paramString

protected String paramString()
この JPasswordField の文字列表現を返します。このメソッドはデバッグ専用であり、返される文字列の内容および形式は実装によって異なります。返される文字列は空の場合がありますが、null にはなりません。

オーバーライド:
クラス JTextField 内の paramString
戻り値:
この JPasswordField の文字列表現

getAccessibleContext

public AccessibleContext getAccessibleContext()
この JPasswordField に関連した AccessibleContext を返します。パスワードフィールドの場合、AccessibleContextAccessibleJPasswordField の形式を取ります。必要に応じて新規の AccessibleJPasswordField インスタンスが作成されます。

定義:
インタフェース Accessible 内の getAccessibleContext
オーバーライド:
クラス JTextField 内の getAccessibleContext
戻り値:
この JPasswordFieldAccessibleContext として機能する AccessibleJPasswordField

JavaTM Platform
Standard Ed. 6

バグの報告と機能のリクエスト
さらに詳しい API リファレンスおよび開発者ドキュメントについては、Java SE 開発者用ドキュメントを参照してください。開発者向けの詳細な解説、概念の概要、用語の定義、バグの回避策、およびコード実例が含まれています。

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。