public class JLabel extends JComponent implements SwingConstants, Accessible
JLabelオブジェクトには、テキスト、イメージまたはその両方を表示できます。垂直方向と水平方向の位置合せ方法を設定することによって、ラベルの表示領域内でのラベル内容の表示場所を指定できます。デフォルトでは、ラベルは表示領域内で垂直方向に中央揃えで配置されます。テキストのみのラベルは、デフォルトではリーディング・エッジに揃えて配置されます。イメージのみのラベルは、デフォルトでは水平方向に中央揃えで配置されます。
また、イメージに対するテキストの位置を相対的に指定することもできます。デフォルトでは、テキストはイメージのトレーリング・エッジに表示され、テキストとイメージは垂直方向にそろえられます。
ラベルのリーディング・エッジおよびトレーリング・エッジは、ComponentOrientationプロパティの値から判定されます。現在では、デフォルトのComponentOrientation設定は、リーディング・エッジが左、トレーリング・エッジが右にマッピングされています。
さらに、setIconTextGapメソッドを使用して、テキストとイメージの間の距離をピクセル数で指定することができます。デフォルトは4ピクセルです。
詳細は、「The Java Tutorial」の「How to Use Labels」を参照してください。
警告: Swingはスレッドに対して安全ではありません。詳細は、「Swing's Threading Policy」を参照してください。
警告: このクラスの直列化されたオブジェクトは、今後のSwingリリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の格納や、同じバージョンのSwingを実行するアプリケーション間のRMIに適しています。1.4以降、すべてのJavaBeans(tm)用の長期間の格納サポートがjava.beansパッケージに追加されています。XMLEncoderを参照してください。
| 修飾子と型 | クラスと説明 |
|---|---|
protected class |
JLabel.AccessibleJLabel
このオブジェクトのAccessible役割を取得するために使用されるクラスです。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| 修飾子と型 | フィールドと説明 |
|---|---|
protected Component |
labelFor |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| コンストラクタと説明 |
|---|
JLabel()
JLabelのインスタンスを、イメージなしの空のタイトル文字列で作成します。 |
JLabel(Icon image)
JLabelのインスタンスを、指定されたイメージで作成します。 |
JLabel(Icon image, int horizontalAlignment)
JLabelのインスタンスを、指定されたイメージと水平方向の配置方法で作成します。 |
JLabel(String text)
JLabelのインスタンスを、指定されたテキストで作成します。 |
JLabel(String text, Icon icon, int horizontalAlignment)
指定されたテキスト、イメージ、および水平方向の配置方法で、
JLabelのインスタンスを作成します。 |
JLabel(String text, int horizontalAlignment)
JLabelのインスタンスを、指定されたテキストと水平方向の配置方法で作成します。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected int |
checkHorizontalKey(int key, String message)
horizontalAlignmentプロパティに対してキーが正当な値であるかどうかを判定します。
|
protected int |
checkVerticalKey(int key, String message)
verticalAlignmentまたはverticalTextPositionプロパティに対してキーが正当な値であるかどうかを判定します。
|
AccessibleContext |
getAccessibleContext()
このオブジェクトのAccessibleContextを取得します。
|
Icon |
getDisabledIcon()
無効な状態のラベルのアイコンを返します。
|
int |
getDisplayedMnemonic()
ニーモニック・キーを示すキー・コードを返します。
|
int |
getDisplayedMnemonicIndex()
Look & Feelがニーモニック文字を表すための修飾を提供する文字をインデックスとして返します。
|
int |
getHorizontalAlignment()
ラベルの内容のX軸に沿った配置方法を返します。
|
int |
getHorizontalTextPosition()
ラベル・テキストのイメージに対する水平位置を返します。
|
Icon |
getIcon()
ラベルに表示するグラフィック・イメージ(グリフやアイコン)を返します。
|
int |
getIconTextGap()
このラベルに表示されているテキストとアイコンとの距離を返します。
|
Component |
getLabelFor()
このラベルが割り当てられているコンポーネントを返します。
|
String |
getText()
ラベルが表示するテキスト文字列を返します。
|
LabelUI |
getUI()
このコンポーネントを描画するL&Fオブジェクトを返します。
|
String |
getUIClassID()
このコンポーネントをレンダリングするL&Fクラスの名前を指定する文字列を返します。
|
int |
getVerticalAlignment()
ラベルの内容のY軸に沿った配置方法を返します。
|
int |
getVerticalTextPosition()
ラベル・テキストのイメージに対する垂直位置を返します。
|
boolean |
imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
現在のIconのImageが、渡されたImage
imgと異なる場合は、オーバーライドされてfalseを返します。 |
protected String |
paramString()
このJLabelの文字列表現を返します。
|
void |
setDisabledIcon(Icon disabledIcon)
このJLabelが無効にされている(JLabel.setEnabled(false)が実行されている)場合に表示されるアイコンを設定します。
|
void |
setDisplayedMnemonic(char aChar)
displayedMnemonicをchar値で設定します。
|
void |
setDisplayedMnemonic(int key)
ニーモニック・キーを示すキー・コードを設定します。
|
void |
setDisplayedMnemonicIndex(int index)
ニーモニックを表すためにテキストのどの文字を装飾するかについてのヒントを、Look & Feelに提供します。
|
void |
setHorizontalAlignment(int alignment)
ラベルの内容のX軸に沿った配置方法を設定します。
|
void |
setHorizontalTextPosition(int textPosition)
ラベル・テキストのイメージに対する水平位置を設定します。
|
void |
setIcon(Icon icon)
このコンポーネントが表示するアイコンを定義します。
|
void |
setIconTextGap(int iconTextGap)
アイコン・プロパティとテキスト・プロパティが両方とも設定されている場合に、このプロパティはそれらの間の距離を定義します。
|
void |
setLabelFor(Component c)
このラベルが割り当てられているコンポーネントを設定します。
|
void |
setText(String text)
このコンポーネントが表示する単一行のテキストを定義する。
|
void |
setUI(LabelUI ui)
このコンポーネントを描画するL&Fオブジェクトを設定します。
|
void |
setVerticalAlignment(int alignment)
ラベルの内容のY軸に沿った配置方法を設定します。
|
void |
setVerticalTextPosition(int textPosition)
ラベルのイメージに対するテキストの垂直位置を設定します。
|
void |
updateUI()
現在のLook & Feelからの値にUIプロパティをリセットします。
|
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, 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, validateTreeaction, 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, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprotected Component labelFor
public JLabel(String text, Icon icon, int horizontalAlignment)
JLabelのインスタンスを作成します。ラベルは、表示領域内で垂直方向に中央揃えされます。テキストはイメージのトレーリング・エッジに表示されます。text - ラベルに表示されるテキスト。icon - ラベルに表示されるイメージ。horizontalAlignment - SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILINGのうちの1つ。public JLabel(String text, int horizontalAlignment)
JLabelのインスタンスを、指定されたテキストと水平方向の配置方法で作成します。ラベルは、表示領域内で垂直方向に中央揃えされます。text - ラベルに表示されるテキスト。horizontalAlignment - SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILINGのうちの1つ。public JLabel(String text)
JLabelのインスタンスを、指定されたテキストで作成します。ラベルは、表示領域のリーディング・エッジにそろえられ、垂直方向に中央揃えされます。text - ラベルに表示されるテキスト。public JLabel(Icon image, int horizontalAlignment)
JLabelのインスタンスを、指定されたイメージと水平方向の配置方法で作成します。ラベルは、表示領域内で垂直方向に中央揃えされます。image - ラベルに表示されるイメージ。horizontalAlignment - SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILINGのうちの1つ。public JLabel(Icon image)
JLabelのインスタンスを、指定されたイメージで作成します。ラベルは、表示領域内で垂直方向と水平方向に中央揃えされます。image - ラベルに表示されるイメージ。public JLabel()
JLabelのインスタンスを、イメージなしの空のタイトル文字列で作成します。ラベルは、表示領域内で垂直方向に中央揃えされます。ラベルの内容が設定されると、ラベルは表示領域のリーディング・エッジに表示されます。public LabelUI getUI()
public void setUI(LabelUI ui)
ui - LabelUI L&FオブジェクトUIDefaults.getUI(javax.swing.JComponent)public void updateUI()
updateUI 、クラス: JComponentJComponent.updateUI()public String getUIClassID()
getUIClassID 、クラス: JComponentJComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)public String getText()
setText(java.lang.String)public void setText(String text)
このプロパティのデフォルト値はnullです。
これはJavaBeansバウンド・プロパティです。
public Icon getIcon()
setIcon(javax.swing.Icon)public void setIcon(Icon icon)
このプロパティのデフォルト値はnullです。
これはJavaBeansバウンド・プロパティです。
public Icon getDisabledIcon()
Look & Feelによっては無効な状態のアイコンがレンダリングされないことがあり、その場合、無効な状態のアイコンは無視されます。
disabledIconプロパティsetDisabledIcon(javax.swing.Icon), LookAndFeel.getDisabledIcon(javax.swing.JComponent, javax.swing.Icon), ImageIconpublic void setDisabledIcon(Icon disabledIcon)
このプロパティのデフォルト値はnullです。
disabledIcon - コンポーネントが無効である場合に表示されるIcongetDisabledIcon(), JComponent.setEnabled(boolean)public void setDisplayedMnemonic(int key)
public void setDisplayedMnemonic(char aChar)
aChar - 表示されるニーモニックを指定するcharsetDisplayedMnemonic(int)public int getDisplayedMnemonic()
getLabelFor(), setLabelFor(java.awt.Component)public void setDisplayedMnemonicIndex(int index)
throws IllegalArgumentException
この値は、ニーモニックの変更(ニーモニック自身またはテキストの変更など)に関連するプロパティとして更新されます。デフォルトの文字を下線付きでないようにする場合、これだけを呼び出す必要があります。たとえば、ニーモニック「a」を持つテキスト「Save As」について、「Save As」のようにAを修飾する場合は、setDisplayedMnemonic(KeyEvent.VK_A)を呼び出してからsetDisplayedMnemonicIndex(5)を呼び出します。
index - 下線を付けるStringに対するインデックスIllegalArgumentException - indexがテキストの長さ以上、または -1より小さい場合にスローされるpublic int getDisplayedMnemonicIndex()
setDisplayedMnemonicIndex(int)protected int checkHorizontalKey(int key,
String message)
key - チェックするプロパティ値message - IllegalArgumentExceptionの詳細メッセージIllegalArgumentException - キーがLEFT、CENTER、RIGHT、LEADING、TRAILINGのどれでもない場合。setHorizontalTextPosition(int), setHorizontalAlignment(int)protected int checkVerticalKey(int key,
String message)
key - チェックするプロパティ値message - IllegalArgumentExceptionの詳細メッセージIllegalArgumentException - キーがTOP、CENTER、またはBOTTOMではない場合。setVerticalAlignment(int), setVerticalTextPosition(int)public int getIconTextGap()
setIconTextGap(int)public void setIconTextGap(int iconTextGap)
このプロパティのデフォルト値は4ピクセルです。
これはJavaBeansバウンド・プロパティです。
getIconTextGap()public int getVerticalAlignment()
SwingConstantsで定義されている定数TOP、CENTER、またはBOTTOMのうちの1つ。SwingConstants, setVerticalAlignment(int)public void setVerticalAlignment(int alignment)
このプロパティのデフォルト値はCENTERです。
alignment - SwingConstantsで定義されている定数TOP、CENTER (デフォルト)、またはBOTTOMのうちの1つ。SwingConstants, getVerticalAlignment()public int getHorizontalAlignment()
SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILINGのうちの1つ。setHorizontalAlignment(int), SwingConstantspublic void setHorizontalAlignment(int alignment)
これはJavaBeansバウンド・プロパティです。
alignment - SwingConstantsで定義されている定数LEFT、CENTER (イメージのみのラベルのデフォルト)、RIGHT、LEADING (テキストのみのラベルのデフォルト)、TRAILINGのうちの1つ。SwingConstants, getHorizontalAlignment()public int getVerticalTextPosition()
SwingConstantsで定義されている定数TOP、CENTER、またはBOTTOMのうちの1つ。setVerticalTextPosition(int), SwingConstantspublic void setVerticalTextPosition(int textPosition)
このプロパティのデフォルト値はCENTERです。
これはJavaBeansバウンド・プロパティです。
textPosition - SwingConstantsで定義されている定数TOP、CENTER (デフォルト)、またはBOTTOMのうちの1つ。SwingConstants, getVerticalTextPosition()public int getHorizontalTextPosition()
SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILINGのうちの1つ。SwingConstantspublic void setHorizontalTextPosition(int textPosition)
textPosition - SwingConstantsで定義されている定数LEFT、CENTER、RIGHT、LEADING、またはTRAILING (デフォルト)のうちの1つ。IllegalArgumentExceptionSwingConstantspublic boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
imgと異なる場合は、オーバーライドされてfalseを返します。imageUpdate 、インタフェース: ImageObserverimageUpdate 、クラス: Componentimg - 監視対象のイメージinfoflags - 詳細は、imageUpdateを参照してくださいx - x座標y - y座標w - 幅h - 高さfalse、そうでない場合はtrue。ImageObserver、Component.imageUpdate(java.awt.Image, int, int, int, int, int)protected String paramString()
nullにはなりません。paramString 、クラス: JComponentpublic Component getLabelFor()
getDisplayedMnemonic(), setDisplayedMnemonic(int)public void setLabelFor(Component c)
c - ラベルが割り当てられているコンポーネント。ラベルがコンポーネントに割り当てられていない場合はnullgetDisplayedMnemonic(), setDisplayedMnemonic(int)public AccessibleContext getAccessibleContext()
getAccessibleContext 、インタフェース: AccessiblegetAccessibleContext、クラス: Component バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright© 1993, 2014, Oracle and/or its affiliates. All rights reserved.