Java プラットフォーム 1.2

javax.swing
クラス JPopupMenu

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPopupMenu
直接の既知のサブクラス:
BasicComboPopup

public class JPopupMenu
extends JComponent
implements Accessible, MenuElement

ポップアップメニューの実装です。ポップアップメニューは小さなウィンドウで、複数の選択肢 (メニューコマンド) を表示します。JPopupMenu は、メニューバー上の項目が選択されたときに表示するメニューに使います。また、選択したメニュー項目によっては表示されることもある、プルライトメニューにも使われます。あるいは、メニューを表示させたい他の場所 (メニューバー以外の場所) でも、JPopupMenu を使えます。たとえば、特定の場所で右クリックが発生した場合のポップアップメニュー表示 (ショートカットメニュー) などです。

標準の Look & Feel (L&F) 表現でこのコンポーネントが使用するキーボードのキーについては、JPopupMenu のキーの割り当てを参照してください。

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

関連項目:
直列化された形式

内部クラスの概要
protected  class JPopupMenu.AccessibleJPopupMenu
           
static class JPopupMenu.Separator
          ポップアップメニュー固有のセパレータです。
 
クラス javax.swing.JComponent から継承した内部クラス
JComponent.AccessibleJComponent
 
クラス 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
 
コンストラクタの概要
JPopupMenu()
          呼び出しコンポーネントの定義なしで JPopupMenu を作成します。
JPopupMenu(String label)
          タイトルを指定して JPopupMenu を作成します。
 
メソッドの概要
 JMenuItem add(Action a)
          メニューの末尾に、指定されたアクションオブジェクトを振り分けるメニュー項目を追加します。
 JMenuItem add(JMenuItem menuItem)
          指定されたメニュー項目をメニューの末尾に追加します。
 JMenuItem add(String s)
          指定されたテキストを持つ新しいメニュー項目を作成して、メニューの末尾に追加します。
 void addPopupMenuListener(PopupMenuListener l)
          PopupMenu のリスナーを追加します。
 void addSeparator()
          メニューの末尾に新しいセパレータを追加します。
protected  PropertyChangeListener createActionChangeListener(JMenuItem b)
           
protected  void firePopupMenuCanceled()
          PopupMenuListener に、ポップアップメニューが取り消されたことを通知します。
protected  void firePopupMenuWillBecomeInvisible()
          PopupMenuListener に、ポップアップメニューが不可視になることを通知します。
protected  void firePopupMenuWillBecomeVisible()
          PopupMenuListener に、ポップアップメニューが可視になることを通知します。
 AccessibleContext getAccessibleContext()
          JComponent に関連付けられている AccessibleContext を取得します。
 Component getComponent()
           
 Component getComponentAtIndex(int i)
          指定されたインデックスのコンポーネントを返します。
 int getComponentIndex(Component c)
          指定されたコンポーネントのインデックスを返します。
static boolean getDefaultLightWeightPopupEnabled()
          lightWeightPopupEnabled プロパティのデフォルト値を返します。
 Component getInvoker()
          ポップアップメニューの呼び出しコンポーネントを返します。
 String getLabel()
          ポップアップメニューのラベルを返します。
 Insets getMargin()
          ポップアップメニューのボーダと内容の間にあるマージンの値を返します。
 SingleSelectionModel getSelectionModel()
          単一の選択を扱うモデルオブジェクトを返します。
 MenuElement[] getSubElements()
           
 PopupMenuUI getUI()
          コンポーネントを描画する L&F オブジェクトを返します。
 String getUIClassID()
          コンポーネントを描画する L&F クラスの名前を返します。
 void insert(Action a, int index)
          指定されたアクションオブジェクトを、メニュー項目として指定の位置に挿入します。
 void insert(Component component, int index)
          指定されたコンポーネントを、メニューの指定された位置に挿入します。
 boolean isBorderPainted()
          ボーダをペイントするかどうかを判定します。
 boolean isLightWeightPopupEnabled()
          軽量 (すべて Java の) ポップアップを使用している場合は true を返し、重量 (ネイティブピアの) ポップアップを使用している場合は false を返します。
 boolean isVisible()
          ポップアップメニューが可視 (現在表示中) である場合に true を返します。
 void menuSelectionChanged(boolean isIncluded)
           
 void pack()
          コンテナをレイアウトして、内容の表示に最小限の空間を使用するようにします。
protected  void paintBorder(Graphics g)
          BorderPainted プロパティが true の場合に、ポップアップメニューのボーダをペイントします。
protected  String paramString()
          この JPopupMenu の文字列表現を返します。
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
           
 void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
           
 void remove(Component comp)
          このポップアップメニューから指定されたコンポーネントを削除します。
 void removePopupMenuListener(PopupMenuListener l)
          PopupMenu のリスナーを削除します。
 void setBorderPainted(boolean b)
          ボーダをペイントするかどうかを設定します。
static void setDefaultLightWeightPopupEnabled(boolean aFlag)
          lightWeightPopupEnabled プロパティのデフォルト値を設定します。
 void setInvoker(Component invoker)
          ポップアップメニューの呼び出しコンポーネントを設定します。
 void setLabel(String label)
          ポップアップメニューのラベルを設定します。
 void setLightWeightPopupEnabled(boolean aFlag)
          ポップアップを表示するとき、適切であれば、JPopupMenu は軽量なポップアップの使用を選択します。
 void setLocation(int x, int y)
          x、y 座標を使って、ポップアップメニューの左上隅の位置を設定します。
 void setPopupSize(Dimension d)
          Dimension オブジェクトを使用して、ポップアップウィンドウのサイズを設定します。
 void setPopupSize(int width, int height)
          ポップアップウィンドウのサイズを、指定された幅および高さに設定します。
 void setSelected(Component sel)
          現在選択されるコンポーネントを設定します。
 void setSelectionModel(SingleSelectionModel model)
          単一の選択を扱うモデルオブジェクトを設定します。
 void setUI(PopupMenuUI ui)
          コンポーネントを描画する L&F オブジェクトを設定します。
 void setVisible(boolean b)
          ポップアップメニューの可視性を設定します。
 void show(Component invoker, int x, int y)
          呼び出しコンポーネント内の x、y 座標で指定された位置に、ポップアップメニューを表示します。
 void updateUI()
          L&F が変更されたことを示す UIFactory からの通知です。
 
クラス javax.swing.JComponent から継承したメソッド
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, 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, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
クラス java.awt.Component から継承したメソッド
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

JPopupMenu

public JPopupMenu()
呼び出しコンポーネントの定義なしで JPopupMenu を作成します。

JPopupMenu

public JPopupMenu(String label)
タイトルを指定して JPopupMenu を作成します。
パラメータ:
label - ポップアップメニューのタイトルとして UI が使う文字列
メソッドの詳細

setDefaultLightWeightPopupEnabled

public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled プロパティのデフォルト値を設定します。

getDefaultLightWeightPopupEnabled

public static boolean getDefaultLightWeightPopupEnabled()
lightWeightPopupEnabled プロパティのデフォルト値を返します。

getUI

public PopupMenuUI getUI()
コンポーネントを描画する L&F オブジェクトを返します。
戻り値:
コンポーネントを描画する PopupMenuUI オブジェクト

setUI

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

updateUI

public void updateUI()
L&F が変更されたことを示す UIFactory からの通知です。UI を UIFactory からの最新バージョンに置き換えるために呼び出されます。
オーバーライド:
クラス JComponent 内の updateUI
関連項目:
JComponent.updateUI()

getUIClassID

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

getSelectionModel

public SingleSelectionModel getSelectionModel()
単一の選択を扱うモデルオブジェクトを返します。
戻り値:
使用中の SingleSelectionModel
関連項目:
SingleSelectionModel

setSelectionModel

public void setSelectionModel(SingleSelectionModel model)
単一の選択を扱うモデルオブジェクトを設定します。
パラメータ:
model - 使用する SingleSelectionModel
関連項目:
SingleSelectionModel

add

public JMenuItem add(JMenuItem menuItem)
指定されたメニュー項目をメニューの末尾に追加します。
パラメータ:
c - 追加する JMenuItem
戻り値:
追加された JMenuItem

add

public JMenuItem add(String s)
指定されたテキストを持つ新しいメニュー項目を作成して、メニューの末尾に追加します。
パラメータ:
s - 追加するメニュー項目に表示する文字列

add

public JMenuItem add(Action a)
メニューの末尾に、指定されたアクションオブジェクトを振り分けるメニュー項目を追加します。
パラメータ:
a - メニューに追加するアクション
関連項目:
Action

remove

public void remove(Component comp)
このポップアップメニューから指定されたコンポーネントを削除します。
パラメータ:
item - メニューから削除する JMenuItem
オーバーライド:
クラス Container 内の remove

createActionChangeListener

protected PropertyChangeListener createActionChangeListener(JMenuItem b)

setLightWeightPopupEnabled

public void setLightWeightPopupEnabled(boolean aFlag)
ポップアップを表示するとき、適切であれば、JPopupMenu は軽量なポップアップの使用を選択します。このメソッドでは、この機能を無効にできます。アプリケーションが軽量コンポーネントと重量コンポーネントを混用する場合には、無効にする必要があります。

isLightWeightPopupEnabled

public boolean isLightWeightPopupEnabled()
軽量 (すべて Java の) ポップアップを使用している場合は true を返し、重量 (ネイティブピアの) ポップアップを使用している場合は false を返します。
戻り値:
軽量ポップアップを使用している場合は true

getLabel

public String getLabel()
ポップアップメニューのラベルを返します。
戻り値:
ポップアップメニューのラベルが格納されている String
関連項目:
setLabel(java.lang.String)

setLabel

public void setLabel(String label)
ポップアップメニューのラベルを設定します。Look & Feel の実装に応じて、ラベルを表示するかどうか選択してもかまいません。
パラメータ:
label - ポップアップメニューのラベルを指定する String
関連項目:
setLabel(java.lang.String)

addSeparator

public void addSeparator()
メニューの末尾に新しいセパレータを追加します。

insert

public void insert(Action a,
                   int index)
指定されたアクションオブジェクトを、メニュー項目として指定の位置に挿入します。
パラメータ:
a - 挿入するアクションオブジェクト
index - アクションを挿入する位置の int 値。0 がメニューの先頭
関連項目:
Action

insert

public void insert(Component component,
                   int index)
指定されたコンポーネントを、メニューの指定された位置に挿入します。
パラメータ:
component - 挿入するコンポーネント
index - アクションを挿入する位置の int 値。0 がメニューの先頭

addPopupMenuListener

public void addPopupMenuListener(PopupMenuListener l)
PopupMenu のリスナーを追加します。
パラメータ:
l - 追加する PopupMenuListener

removePopupMenuListener

public void removePopupMenuListener(PopupMenuListener l)
PopupMenu のリスナーを削除します。
パラメータ:
l - 削除する PopupMenuListener

firePopupMenuWillBecomeVisible

protected void firePopupMenuWillBecomeVisible()
PopupMenuListener に、ポップアップメニューが可視になることを通知します。

firePopupMenuWillBecomeInvisible

protected void firePopupMenuWillBecomeInvisible()
PopupMenuListener に、ポップアップメニューが不可視になることを通知します。

firePopupMenuCanceled

protected void firePopupMenuCanceled()
PopupMenuListener に、ポップアップメニューが取り消されたことを通知します。

pack

public void pack()
コンテナをレイアウトして、内容の表示に最小限の空間を使用するようにします。

setVisible

public void setVisible(boolean b)
ポップアップメニューの可視性を設定します。
パラメータ:
b - ポップアップを可視にする場合は true、不可視にする場合は false
オーバーライド:
クラス JComponent 内の setVisible

isVisible

public boolean isVisible()
ポップアップメニューが可視 (現在表示中) である場合に true を返します。
オーバーライド:
クラス Component 内の isVisible

setLocation

public void setLocation(int x,
                        int y)
x、y 座標を使って、ポップアップメニューの左上隅の位置を設定します。
パラメータ:
x - ポップアップメニューの新しい位置の x 座標
y - ポップアップメニューの新しい位置の y 座標
オーバーライド:
クラス Component 内の setLocation

getInvoker

public Component getInvoker()
ポップアップメニューの呼び出しコンポーネントを返します。
戻り値:
ポップアップメニューが表示されるコンポーネント

setInvoker

public void setInvoker(Component invoker)
ポップアップメニューの呼び出しコンポーネントを設定します。すなわち、ポップアップメニュー項目が表示されるコンポーネントです。
パラメータ:
invoker - ポップアップメニューが表示されるコンポーネント

show

public void show(Component invoker,
                 int x,
                 int y)
呼び出しコンポーネント内の x、y 座標で指定された位置に、ポップアップメニューを表示します。
パラメータ:
invoker - ポップアップメニューが表示されるコンポーネント
x - ポップアップメニューを表示する呼び出しコンポーネントの x 座標
y - ポップアップメニューを表示する呼び出しコンポーネントの y 座標

getComponentIndex

public int getComponentIndex(Component c)
指定されたコンポーネントのインデックスを返します。
パラメータ:
c - 検索するコンポーネント
戻り値:
コンポーネントのインデックス。0 が先頭。コンポーネントがなければ -1

getComponentAtIndex

public Component getComponentAtIndex(int i)
指定されたインデックスのコンポーネントを返します。
パラメータ:
i - コンポーネントのインデックス。0 が先頭
戻り値:
指定されたインデックスのコンポーネント

setPopupSize

public void setPopupSize(Dimension d)
Dimension オブジェクトを使用して、ポップアップウィンドウのサイズを設定します。
パラメータ:
d - コンポーネントの新しいサイズを指定する寸法

setPopupSize

public void setPopupSize(int width,
                         int height)
ポップアップウィンドウのサイズを、指定された幅および高さに設定します。
パラメータ:
width - ポップアップの新しい幅 (ピクセル)
height - ポップアップの新しい高さ (ピクセル)

setSelected

public void setSelected(Component sel)
現在選択されるコンポーネントを設定します。結果として、選択モデルが変更されます。
パラメータ:
sel - 選択するコンポーネント

isBorderPainted

public boolean isBorderPainted()
ボーダをペイントするかどうかを判定します。
戻り値:
ボーダをペイントする場合は true
関連項目:
setBorderPainted(boolean)

setBorderPainted

public void setBorderPainted(boolean b)
ボーダをペイントするかどうかを設定します。
パラメータ:
b - true の場合はボーダをペイント
関連項目:
isBorderPainted()

paintBorder

protected void paintBorder(Graphics g)
BorderPainted プロパティが true の場合に、ポップアップメニューのボーダをペイントします。
オーバーライド:
クラス JComponent 内の paintBorder
関連項目:
JComponent.paint(java.awt.Graphics), JComponent.setBorder(javax.swing.border.Border)

getMargin

public Insets getMargin()
ポップアップメニューのボーダと内容の間にあるマージンの値を返します。
戻り値:
マージンの値を含む Insets オブジェクト

paramString

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

JFC コンポーネントの新しい側面についての情報を返すには、paramString() をオーバーライドします。

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

getAccessibleContext

public AccessibleContext getAccessibleContext()
JComponent に関連付けられている AccessibleContext を取得します。
定義:
インタフェース Accessible 内の getAccessibleContext
戻り値:
JComponent の AccessibleContext
オーバーライド:
クラス JComponent 内の getAccessibleContext

processMouseEvent

public void processMouseEvent(MouseEvent event,
                              MenuElement[] path,
                              MenuSelectionManager manager)
定義:
インタフェース MenuElement 内の processMouseEvent

processKeyEvent

public void processKeyEvent(KeyEvent e,
                            MenuElement[] path,
                            MenuSelectionManager manager)
定義:
インタフェース MenuElement 内の processKeyEvent

menuSelectionChanged

public void menuSelectionChanged(boolean isIncluded)
定義:
インタフェース MenuElement 内の menuSelectionChanged

getSubElements

public MenuElement[] getSubElements()
定義:
インタフェース MenuElement 内の getSubElements

getComponent

public Component getComponent()
定義:
インタフェース MenuElement 内の getComponent

Java プラットフォーム 1.2

バグや機能要求の報告
新しい javadoc の表示についてのコメントやご提案
Java は、米国およびその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.