JavaTM 2 Platform
Std. Ed. v1.3

javax.swing
クラス JMenuItem

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.AbstractButton
                          |
                          +--javax.swing.JMenuItem
すべての実装インタフェース:
Accessible, ImageObserver, ItemSelectable, MenuContainer, MenuElement, Serializable, SwingConstants
直系の既知のサブクラス:
JCheckBoxMenuItem, JMenu, JRadioButtonMenuItem

public class JMenuItem
extends AbstractButton
implements Accessible, MenuElement

メニューの項目の実装です。メニュー項目は実質的にはリストに置かれているボタンです。ユーザが「ボタン」を選択すると、メニュー項目に対応するアクションが実行されます。機能は JPopupMenu が保持する JMenuItem で正確に実行されます。

詳細と例については、「The Java Tutorial」「How to Use Menus」を参照してください。標準の Look & Feel (L&F) 表現でこのコンポーネントが使うキーボードのキーについては、JMenuItem のキー割り当てを参照してください。

警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の運用や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。今後の Swing リリースでは、長期間の持続性をサポートする予定です。

関連項目:
JPopupMenu, JMenu, JCheckBoxMenuItem, JRadioButtonMenuItem, 直列化された形式

内部クラスの概要
protected  class JMenuItem.AccessibleJMenuItem
          このクラスは JMenuItem クラス用のユーザ補助機能のサポートを実装しています。
 
クラス javax.swing.AbstractButton から継承した内部クラス
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
クラス javax.swing.JComponent から継承した内部クラス
JComponent.AccessibleJComponent
 
クラス java.awt.Container から継承した内部クラス
Container.AccessibleAWTContainer
 
クラス java.awt.Component から継承した内部クラス
Component.AccessibleAWTComponent
 
クラス javax.swing.AbstractButton から継承したフィールド
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
クラス 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, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
インタフェース java.awt.image.ImageObserver から継承したフィールド
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
コンストラクタの概要
JMenuItem()
          テキストまたはアイコンのないメニュー項目を作成します。
JMenuItem(Action a)
          指定された Action からプロパティを取得するメニュー項目を作成します。
JMenuItem(Icon icon)
          アイコンのあるメニュー項目を作成します。
JMenuItem(String text)
          テキストのあるメニュー項目を作成します。
JMenuItem(String text, Icon icon)
          指定されたテキストおよびアイコンでメニュー項目を作成します。
JMenuItem(String text, int mnemonic)
          指定されたテキストおよびキーボードニーモニックでメニュー項目を作成します。
 
メソッドの概要
 void addMenuDragMouseListener(MenuDragMouseListener l)
          メニュー項目に MenuDragMouseListener を追加します。
 void addMenuKeyListener(MenuKeyListener l)
          メニュー項目に MenuKeyListener を追加します。
protected  void configurePropertiesFromAction(Action a)
          Action インスタンスの値に従って ActionEvent ソースのプロパティを設定するファクトリメソッドです。
protected  PropertyChangeListener createActionPropertyChangeListener(Action a)
          指定された Action インスタンスでプロパティが変更するように ActionEvent ソースを更新するのに使う PropertyChangeListener を生成するファクトリメソッドです。
protected  void fireMenuDragMouseDragged(MenuDragMouseEvent event)
           
protected  void fireMenuDragMouseEntered(MenuDragMouseEvent event)
           
protected  void fireMenuDragMouseExited(MenuDragMouseEvent event)
           
protected  void fireMenuDragMouseReleased(MenuDragMouseEvent event)
           
protected  void fireMenuKeyPressed(MenuKeyEvent event)
           
protected  void fireMenuKeyReleased(MenuKeyEvent event)
           
protected  void fireMenuKeyTyped(MenuKeyEvent event)
           
 KeyStroke getAccelerator()
          メニュー項目のアクセラレータとして機能する KeyStroke を返します。
 AccessibleContext getAccessibleContext()
          この JMenuItem に関連した AccessibleContext を返します。
 Component getComponent()
          該当のオブジェクトをペイントするための java.awt.Component を返します。
 MenuElement[] getSubElements()
          該当のメニューコンポーネントのサブメニューコンポーネントを保持する配列を返します。
 String getUIClassID()
          このコンポーネントを描画する L&F クラスの名前を返します。
protected  void init(String text, Icon icon)
          指定されたテキストおよびアイコンでメニュー項目を初期化します。
 boolean isArmed()
          メニュー項目の「作動準備が整っている」かどうかを返します。
 void menuSelectionChanged(boolean isIncluded)
          MenuElement が選択されるか選択を解除されると MenuSelectionManager から呼び出されます。
protected  String paramString()
          この JMenuItem の文字列表現を返します。
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
          MenuSelectionManager から転送されるキーイベントを処理します。
 void processMenuDragMouseEvent(MenuDragMouseEvent e)
          メニューでのマウスドラッグを処理します。
 void processMenuKeyEvent(MenuKeyEvent e)
          メニューのキーストロークを処理します。
 void processMouseEvent(MouseEvent e, MenuElement[] path, MenuSelectionManager manager)
          MenuSelectionManager から転送されるマウスイベントを処理します。
 void removeMenuDragMouseListener(MenuDragMouseListener l)
          メニュー項目から MenuDragMouseListener を削除します。
 void removeMenuKeyListener(MenuKeyListener l)
          メニュー項目から MenuKeyListener を削除します。
 void setAccelerator(KeyStroke keyStroke)
          メニュー階層を移動することなくメニュー項目のアクションリスナーを呼び出すキーの組み合わせを設定します。
 void setArmed(boolean b)
          メニュー項目を「作動準備が整っている」ものとして設定します。
 void setEnabled(boolean b)
          メニュー項目を有効または無効にします。
 void setUI(MenuItemUI ui)
          このコンポーネントを描画する L&F オブジェクトを設定します。
 void updateUI()
          現在の Look & Feel からの値を持つ UI プロパティをリセットします。
 
クラス javax.swing.AbstractButton から継承したメソッド
addActionListener, addChangeListener, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getDisabledIcon, getDisabledSelectedIcon, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getLabel, getMargin, getMnemonic, getModel, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isFocusTraversable, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setLabel, setMargin, setMnemonic, setMnemonic, setModel, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
クラス javax.swing.JComponent から継承したメソッド
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
クラス java.awt.Container から継承したメソッド
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
クラス java.awt.Component から継承したメソッド
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

JMenuItem

public JMenuItem()
テキストまたはアイコンのないメニュー項目を作成します。

JMenuItem

public JMenuItem(Icon icon)
アイコンのあるメニュー項目を作成します。
パラメータ:
icon - MenuItem のアイコン

JMenuItem

public JMenuItem(String text)
テキストのあるメニュー項目を作成します。
パラメータ:
text - MenuItem のテキスト

JMenuItem

public JMenuItem(Action a)
指定された Action からプロパティを取得するメニュー項目を作成します。
導入されたバージョン:
1.3

JMenuItem

public JMenuItem(String text,
                 Icon icon)
指定されたテキストおよびアイコンでメニュー項目を作成します。
パラメータ:
text - メニュー項目のテキスト
icon - メニュー項目のアイコン

JMenuItem

public JMenuItem(String text,
                 int mnemonic)
指定されたテキストおよびキーボードニーモニックでメニュー項目を作成します。
パラメータ:
text - メニュー項目のテキスト
mnemonic - メニュー項目のキーボードニーモニック
メソッドの詳細

init

protected void init(String text,
                    Icon icon)
指定されたテキストおよびアイコンでメニュー項目を初期化します。
オーバーライド:
クラス AbstractButton 内の init
パラメータ:
text - メニュー項目のテキスト
icon - メニュー項目のアイコン

setUI

public void setUI(MenuItemUI ui)
このコンポーネントを描画する L&F オブジェクトを設定します。
パラメータ:
ui - MenuItem の UI L&F オブジェクト
関連項目:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
現在の Look & Feel からの値を持つ UI プロパティをリセットします。
オーバーライド:
クラス AbstractButton 内の updateUI
関連項目:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
このコンポーネントを描画する L&F クラスの名前を返します。
オーバーライド:
クラス JComponent 内の getUIClassID
戻り値:
MenuItemUI
関連項目:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setArmed

public void setArmed(boolean b)
メニュー項目を「作動準備が整っている」ものとして設定します。この項目上でマウスボタンが離されると、メニューのアクションイベントがトリガーされます。それ以外の場所でマウスボタンが離されると、イベントはトリガーされずメニュー項目の作動準備は解除されます。
パラメータ:
b - メニュー項目の作動準備を整え、選択可能にする場合は true

isArmed

public boolean isArmed()
メニュー項目の「作動準備が整っている」かどうかを返します。
戻り値:
メニュー項目の作動準備が整っていて選択可能な場合は true
関連項目:
setArmed(boolean)

setEnabled

public void setEnabled(boolean b)
メニュー項目を有効または無効にします。
オーバーライド:
クラス AbstractButton 内の setEnabled
パラメータ:
b - 項目を有効にする場合は true

setAccelerator

public void setAccelerator(KeyStroke keyStroke)
メニュー階層を移動することなくメニュー項目のアクションリスナーを呼び出すキーの組み合わせを設定します。適切なアクションをインストールするのは UI の役割です。
パラメータ:
keyStroke - アクセラレータとして機能する KeyStroke

getAccelerator

public KeyStroke getAccelerator()
メニュー項目のアクセラレータとして機能する KeyStroke を返します。
戻り値:
アクセラレータキーを識別する KeyStroke オブジェクト

configurePropertiesFromAction

protected void configurePropertiesFromAction(Action a)
Action インスタンスの値に従って ActionEvent ソースのプロパティを設定するファクトリメソッドです。設定されるプロパティはサブクラスによって異なります。デフォルトでは、設定されるプロパティは Text および Icon です。
オーバーライド:
クラス AbstractButton 内の configurePropertiesFromAction
パラメータ:
a - プロパティの取得元 Action、または null
導入されたバージョン:
1.3
関連項目:
Action, AbstractButton.setAction(javax.swing.Action)

createActionPropertyChangeListener

protected PropertyChangeListener createActionPropertyChangeListener(Action a)
指定された Action インスタンスでプロパティが変更するように ActionEvent ソースを更新するのに使う PropertyChangeListener を生成するファクトリメソッドです。最新の状態で保持する必要のあるプロパティのセットがデフォルトプロパティと異なる場合は、独自の PropertyChangeListener を提供するためにサブクラスがこのメソッドをオーバーライドします。 PropertyChangeListener は ActionEvent ソースへの強い参照を保持しないようにする必要があります。これは、ActionEvent ソースのガベージコレクションおよびすべての包含関係の階層のコンポーネントを妨害する可能性があるからです。
オーバーライド:
クラス AbstractButton 内の createActionPropertyChangeListener
導入されたバージョン:
1.3
関連項目:
Action, AbstractButton.setAction(javax.swing.Action)

processMouseEvent

public void processMouseEvent(MouseEvent e,
                              MenuElement[] path,
                              MenuSelectionManager manager)
MenuSelectionManager から転送されるマウスイベントを処理します。
定義:
インタフェース MenuElement 内の processMouseEvent
パラメータ:
event - ソースが受信側コンポーネントとなる MouseEvent
componentPath - 受信側コンポーネントに対する MenuElement のパス配列
manager - メニュー階層の MenuSelectionManager。このメソッドは、MouseEvent を処理し、必要に応じて MenuSelectionManager の API を使用して、メニュー選択を変更しなければならない

注: イベントをサブコンポーネントに転送する必要はありません。MenuSelectionManager が自動的に実行します。


processKeyEvent

public void processKeyEvent(KeyEvent e,
                            MenuElement[] path,
                            MenuSelectionManager manager)
MenuSelectionManager から転送されるキーイベントを処理します。
定義:
インタフェース MenuElement 内の processKeyEvent
パラメータ:
event - ソースが受信側コンポーネントとなる KeyEvent
componentPath - 受信側コンポーネントに対する MenuElement のパスの配列
manager - メニュー階層の MenuSelectionManager。このメソッドは、KeyEvent を処理し、必要に応じて MenuSelectionManager の API を使用して、メニュー選択を変更しなければならない

注: イベントをサブコンポーネントに転送する必要はありません。MenuSelectionManager が自動的に実行します。


processMenuDragMouseEvent

public void processMenuDragMouseEvent(MenuDragMouseEvent e)
メニューでのマウスドラッグを処理します。
パラメータ:
e - MenuDragMouseEvent オブジェクト

processMenuKeyEvent

public void processMenuKeyEvent(MenuKeyEvent e)
メニューのキーストロークを処理します。
パラメータ:
e - MenuKeyEvent オブジェクト

fireMenuDragMouseEntered

protected void fireMenuDragMouseEntered(MenuDragMouseEvent event)

fireMenuDragMouseExited

protected void fireMenuDragMouseExited(MenuDragMouseEvent event)

fireMenuDragMouseDragged

protected void fireMenuDragMouseDragged(MenuDragMouseEvent event)

fireMenuDragMouseReleased

protected void fireMenuDragMouseReleased(MenuDragMouseEvent event)

fireMenuKeyPressed

protected void fireMenuKeyPressed(MenuKeyEvent event)

fireMenuKeyReleased

protected void fireMenuKeyReleased(MenuKeyEvent event)

fireMenuKeyTyped

protected void fireMenuKeyTyped(MenuKeyEvent event)

menuSelectionChanged

public void menuSelectionChanged(boolean isIncluded)
MenuElement が選択されるか選択を解除されると MenuSelectionManager から呼び出されます。
定義:
インタフェース MenuElement 内の menuSelectionChanged
パラメータ:
isIncluded - このメニュー項目がメニューパスの変更部分にある場合は true、このメニューは変更されたメニューパスの一部であるがこの項目の部分が変更されていない場合は false
関連項目:
MenuSelectionManager.setSelectedPath(MenuElement[])

getSubElements

public MenuElement[] getSubElements()
該当のメニューコンポーネントのサブメニューコンポーネントを保持する配列を返します。
定義:
インタフェース MenuElement 内の getSubElements
戻り値:
MenuElement の配列

getComponent

public Component getComponent()
該当のオブジェクトをペイントするための java.awt.Component を返します。返されるコンポーネントを使用して、イベントの変換およびイベントがメニューコンポーネント内にあるかどうかの判定を行います。
定義:
インタフェース MenuElement 内の getComponent
戻り値:
このメニュー項目をペイントする Component

addMenuDragMouseListener

public void addMenuDragMouseListener(MenuDragMouseListener l)
メニュー項目に MenuDragMouseListener を追加します。

removeMenuDragMouseListener

public void removeMenuDragMouseListener(MenuDragMouseListener l)
メニュー項目から MenuDragMouseListener を削除します。

addMenuKeyListener

public void addMenuKeyListener(MenuKeyListener l)
メニュー項目に MenuKeyListener を追加します。

removeMenuKeyListener

public void removeMenuKeyListener(MenuKeyListener l)
メニュー項目から MenuKeyListener を削除します。

paramString

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

getAccessibleContext

public AccessibleContext getAccessibleContext()
この JMenuItem に関連した AccessibleContext を返します。JMenuItem の場合、AccessibleContext は AccessibleJMenuItem の形式を取ります。必要に応じて新規の AccessibleJMenuItem インスタンスが作成されます。
定義:
インタフェース Accessible 内の getAccessibleContext
オーバーライド:
クラス JComponent 内の getAccessibleContext
戻り値:
この JMenuItem の AccessibleContext として機能する AccessibleJMenuItem

JavaTM 2 Platform
Std. Ed. v1.3

バグや機能要求の報告
さらに詳しい API リファレンスおよび開発者ドキュメントについては、 Java 2 SDK SE Developer Documentation を参照してください。このドキュメントには、概念、用語の定義、回避策、 実用的なコード例など、開発者を対象にした詳細な解説が掲載されています。

Java、Java 2D、JDBC は、米国およびその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.