|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPopupMenu
public class JPopupMenu
彈出選單的實作,彈出選單是一個可彈出並顯示一系列選項的小視窗。JPopupMenu 用於使用者在選單欄上選擇項時顯示的選單。它還用於當使用者選擇選單項並啟動它時顯示的“右拉式 (pull-right)”選單。最後,JPopupMenu 還可以在想讓選單顯示的任何其他位置使用。例如,當使用者在指定區域中右擊時。
有關使用彈出選單的範例和資訊,請參閱 The Java Tutorial 中的 How to Use Menus。
警告:Swing 不是執行緒安全的。有關更多資訊,請參閱 Swing's Threading Policy。
警告:此類別的序列化物件與以後的 Swing 版本不相容。當前序列化支持適用於短期存儲,或適用於在運行相同 Swing 版本的應用程序之間進行 RMI(Remote Method Invocation,遠端方法調用)。從 1.4 版本開始,已在 java.beans 套件中添加了支持所有 JavaBeansTM 長期存儲的功能。請參見 XMLEncoder。
| 巢狀類別摘要 | |
|---|---|
protected class |
JPopupMenu.AccessibleJPopupMenu
此類別實作 JPopupMenu 類別的可存取性支持。 |
static class |
JPopupMenu.Separator
彈出與選單有關的分隔符。 |
| 從類別 javax.swing.JComponent 繼承的巢狀類別/介面 |
|---|
JComponent.AccessibleJComponent |
| 從類別 java.awt.Container 繼承的巢狀類別/介面 |
|---|
Container.AccessibleAWTContainer |
| 從類別 java.awt.Component 繼承的巢狀類別/介面 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 欄位摘要 |
|---|
| 從類別 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 |
| 從介面 java.awt.image.ImageObserver 繼承的欄位 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 建構子摘要 | |
|---|---|
JPopupMenu()
建構一個不帶“調用者”的 JPopupMenu。 |
|
JPopupMenu(String label)
建構一個具有指定標題的 JPopupMenu。 |
|
| 方法摘要 | |
|---|---|
JMenuItem |
add(Action a)
將指派指定 Action 物件的新選單項添加到選單的末尾。 |
JMenuItem |
add(JMenuItem menuItem)
將指定選單項添加到此選單的末尾。 |
JMenuItem |
add(String s)
創建具有指定文本的選單項,並將其添加到此選單的末尾。 |
void |
addMenuKeyListener(MenuKeyListener l)
將 MenuKeyListener 添加到彈出選單。 |
void |
addPopupMenuListener(PopupMenuListener l)
添加 PopupMenu 偵聽器。 |
void |
addSeparator()
將新分隔符添加到選單的末尾。 |
protected PropertyChangeListener |
createActionChangeListener(JMenuItem b)
返回一個正確配置的 PropertyChangeListener,它在 Action 發生更改時更新控制元件。 |
protected JMenuItem |
createActionComponent(Action a)
該處理器方法為添加到 JPopupMenu 的 Action 創建對應的 JMenuItem。 |
protected void |
firePopupMenuCanceled()
通知 PopupMenuListener 此彈出選單將被取消。 |
protected void |
firePopupMenuWillBecomeInvisible()
通知 PopupMenuListener 此彈出選單將變得不可見。 |
protected void |
firePopupMenuWillBecomeVisible()
通知 PopupMenuListener 此彈出選單將變得可見。 |
AccessibleContext |
getAccessibleContext()
獲取與此 JPopupMenu 關聯的 AccessibleContext。 |
Component |
getComponent()
返回此 JPopupMenu 元件。 |
Component |
getComponentAtIndex(int i)
已過時。 由 Container.getComponent(int) 取代 |
int |
getComponentIndex(Component c)
返回指定元件的索引。 |
static boolean |
getDefaultLightWeightPopupEnabled()
獲取 defaultLightWeightPopupEnabled 屬性,預設情況下,該屬性為 true。 |
Component |
getInvoker()
返回作為此彈出選單的“調用者”的元件。 |
String |
getLabel()
返回彈出選單的標籤。 |
Insets |
getMargin()
返回彈出選單的邊框與其包含內容之間的空白(以像素表示)。 |
MenuKeyListener[] |
getMenuKeyListeners()
返回利用 addMenuKeyListener() 添加到此 JPopupMenu 的所有 MenuKeyListener 組成的陣列。 |
PopupMenuListener[] |
getPopupMenuListeners()
返回利用 addPopupMenuListener() 添加到此 JMenuItem 的所有 PopupMenuListener 組成的陣列。 |
SingleSelectionModel |
getSelectionModel()
返回處理單個選擇的模型物件。 |
MenuElement[] |
getSubElements()
返回 MenuElement 組成的陣列,包含此選單元件的子選單。 |
PopupMenuUI |
getUI()
返回用於呈現此元件的外觀 (L&F) 物件。 |
String |
getUIClassID()
返回用於呈現此元件的 L&F 類別名。 |
void |
insert(Action a,
int index)
在給定位置插入指定 Action 物件的選單項。 |
void |
insert(Component component,
int index)
將指定元件插入到選單的給定位置。 |
boolean |
isBorderPainted()
檢查是否應該繪製邊框。 |
boolean |
isLightWeightPopupEnabled()
獲取 lightWeightPopupEnabled 屬性。 |
boolean |
isPopupTrigger(MouseEvent e)
如果 JPopupMenu 的當前安裝 UI 將 MouseEvent 視為彈出選單觸發器,則返回 true。 |
boolean |
isVisible()
如果彈出選單可見(當前顯示的),則返回 true。 |
void |
menuSelectionChanged(boolean isIncluded)
當選單欄選擇發生更改以啟動或取消啟動此選單時傳遞訊息。 |
void |
pack()
佈置容器,讓它使用顯示其內容所需的最小空間。 |
protected void |
paintBorder(Graphics g)
如果 borderPainted 屬性為 true,則繪製彈出選單的邊框。 |
protected String |
paramString()
返回此 JPopupMenu 的字元串表示形式。 |
protected void |
processFocusEvent(FocusEvent evt)
處理元件上發生的焦點事件,方法是將其指派到任意已註冊的 FocusListener 物件。 |
protected void |
processKeyEvent(KeyEvent evt)
處理快捷鍵事件,如助記符和加速器。 |
void |
processKeyEvent(KeyEvent e,
MenuElement[] path,
MenuSelectionManager manager)
如有必要,通過使用 MenuSelectionManager 的 API 處理從 MenuSelectionManager 轉發的鍵事件並更改選單選擇。 |
void |
processMouseEvent(MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
要求此方法遵守 MenuElement 介面,但它沒有被實作。 |
void |
remove(int pos)
從此彈出選單移除指定索引處的元件。 |
void |
removeMenuKeyListener(MenuKeyListener l)
從彈出選單移除 MenuKeyListener。 |
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)
設置 lightWeightPopupEnabled 屬性的值,預設情況下該值為 true。 |
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()
將 UI 屬性重置為一個來自當前外觀的值。 |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 建構子詳細資訊 |
|---|
public JPopupMenu()
JPopupMenu。
public JPopupMenu(String label)
JPopupMenu。
label - 可以被 UI 用作彈出選單的標題顯示的字元串。| 方法詳細資訊 |
|---|
public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled 屬性的預設值。
aFlag - 如果彈出選單為輕量級,則為 true;否則為 falsegetDefaultLightWeightPopupEnabled(),
setLightWeightPopupEnabled(boolean)public static boolean getDefaultLightWeightPopupEnabled()
defaultLightWeightPopupEnabled 屬性,預設情況下,該屬性為 true。
defaultLightWeightPopupEnabled 屬性的值setDefaultLightWeightPopupEnabled(boolean)public PopupMenuUI getUI()
PopupMenuUI 物件public void setUI(PopupMenuUI ui)
ui - 新 PopupMenuUI L&F 物件UIDefaults.getUI(javax.swing.JComponent)public void updateUI()
JComponent 中的 updateUIJComponent.updateUI()public String getUIClassID()
JComponent 中的 getUIClassIDJComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)protected void processFocusEvent(FocusEvent evt)
Component 複製的描述FocusListener 物件。
如果元件上沒有啟用焦點事件,則不調用此方法。發生下列之一時啟用焦點事件:
addFocusListener 註冊了一個 FocusListener 物件。
enableEvents 啟用了焦點事件。
如果為某個 Component 啟用了焦點事件,則當前的 KeyboardFocusManager 確定是否應該將焦點事件指派到已註冊的 FocusListener 物件。如果未指派事件,則 KeyboardFocusManager 調用 Component 的 dispatchEvent 方法,此方法又調用 Component 的 processFocusEvent 方法。
如果為 Component 啟用了焦點事件,則用 FocusEvent 作為參數來調用 Component 的 dispatchEvent 方法將導致調用 Component 的 processFocusEvent 方法,而不管當前的 KeyboardFocusManager 如何。
注意,如果事件參數為 null,則未指定行為並且可能導致異常。
Component 中的 processFocusEventevt - 焦點事件FocusEvent,
FocusListener,
KeyboardFocusManager,
Component.addFocusListener(java.awt.event.FocusListener),
Component.enableEvents(long),
Component.dispatchEvent(java.awt.AWTEvent)protected void processKeyEvent(KeyEvent evt)
JComponent 中的 processKeyEventevt - 要處理的鍵事件KeyEvent,
KeyListener,
KeyboardFocusManager,
DefaultKeyboardFocusManager,
Component.processEvent(java.awt.AWTEvent),
Component.dispatchEvent(java.awt.AWTEvent),
Component.addKeyListener(java.awt.event.KeyListener),
Component.enableEvents(long),
Component.isShowing()public SingleSelectionModel getSelectionModel()
selectionModel 屬性SingleSelectionModelpublic void setSelectionModel(SingleSelectionModel model)
model - 新 SingleSelectionModelSingleSelectionModelpublic JMenuItem add(JMenuItem menuItem)
menuItem - 要添加的 JMenuItem
JMenuItempublic JMenuItem add(String s)
s - 要添加的選單項的字元串public JMenuItem add(Action a)
Action 物件的新選單項添加到選單的末尾。
a - 要添加到選單的 Action
Actionprotected JMenuItem createActionComponent(Action a)
JPopupMenu 的 Action 創建對應的 JMenuItem。
a - 要添加的選單項的 Action
Actionprotected PropertyChangeListener createActionChangeListener(JMenuItem b)
PropertyChangeListener,它在 Action 發生更改時更新控制元件。
public void remove(int pos)
Container 中的 removepos - 要移除的項的位置
IllegalArgumentException - 如果 pos 的值 < 0 或者 pos 的值大於項數Container.add(java.awt.Component),
Container.validate(),
Container.getComponentCount()public void setLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled 屬性的值,預設情況下該值為 true。預設情況下,當外觀顯示彈出選單時,它選擇使用輕量級(純 Java 的)彈出選單。輕量級彈出視窗比重量級(本機同位體)視窗效果更好,但是輕量級和重量級元件在 GUI 中不能很好地混合使用。如果應用程序混合使用輕量級和重量級元件,則應該禁用輕量級彈出視窗。某些外觀可能始終使用重量級彈出選單,不管此屬性的值如何。
aFlag - 為 false 表示禁用輕量級彈出選單isLightWeightPopupEnabled()public boolean isLightWeightPopupEnabled()
lightWeightPopupEnabled 屬性。
lightWeightPopupEnabled 屬性的值setLightWeightPopupEnabled(boolean)public String getLabel()
setLabel(java.lang.String)public void setLabel(String label)
label - 指定彈出選單標籤的字元串setLabel(java.lang.String)public void addSeparator()
public void insert(Action a,
int index)
Action 物件的選單項。
a - 要插入的 Action 物件index - 指定插入 Action 的位置,其中 0 為第一個
IllegalArgumentException - 如果 index < 0Action
public void insert(Component component,
int index)
component - 要插入的 Componentindex - 指定插入元件的位置,其中 0 為第一個
IllegalArgumentException - 如果 index < 0public void addPopupMenuListener(PopupMenuListener l)
PopupMenu 偵聽器。
l - 要添加的 PopupMenuListenerpublic void removePopupMenuListener(PopupMenuListener l)
PopupMenu 偵聽器。
l - 要移除的 PopupMenuListenerpublic PopupMenuListener[] getPopupMenuListeners()
PopupMenuListener 組成的陣列。
PopupMenuListener,如果沒有添加偵聽器,則返回一個空陣列public void addMenuKeyListener(MenuKeyListener l)
MenuKeyListener 添加到彈出選單。
l - 要添加的 MenuKeyListenerpublic void removeMenuKeyListener(MenuKeyListener l)
MenuKeyListener。
l - 要移除的 MenuKeyListenerpublic MenuKeyListener[] getMenuKeyListeners()
MenuKeyListener 組成的陣列。
MenuKeyListener,如果沒有添加偵聽器,則返回一個空陣列protected void firePopupMenuWillBecomeVisible()
PopupMenuListener 此彈出選單將變得可見。
protected void firePopupMenuWillBecomeInvisible()
PopupMenuListener 此彈出選單將變得不可見。
protected void firePopupMenuCanceled()
PopupMenuListener 此彈出選單將被取消。
public void pack()
public void setVisible(boolean b)
JComponent 中的 setVisibleb - 為 true 表示使彈出選單可見,為 false 表示隱藏它Component.isVisible()public boolean isVisible()
Component 中的 isVisibletrue;否則返回 falseComponent.setVisible(boolean)
public void setLocation(int x,
int y)
Component 中的 setLocationx - 螢幕坐標空間中彈出選單的新位置的 X 坐標y - 螢幕坐標空間中彈出選單的新位置的 Y 坐標Component.getLocation(),
Component.setBounds(int, int, int, int)public Component getInvoker()
Componentpublic void setInvoker(Component invoker)
invoker - 彈出選單在其中顯示的 Component
public void show(Component invoker,
int x,
int y)
invoker - 彈出選單在其空間中顯示的元件x - 用於顯示彈出選單的調用者的坐標空間中的 X 坐標y - 用於顯示彈出選單的調用者的坐標空間中的 Y 坐標@Deprecated public Component getComponentAtIndex(int i)
Container.getComponent(int) 取代
i - 元件的索引,其中 0 為第一個
Componentpublic int getComponentIndex(Component c)
c - 要尋找的 Component
public void setPopupSize(Dimension d)
Dimension 物件設置彈出視窗的大小。此操作等效於 setPreferredSize(d)。
d - 指定此元件新的大小的 Dimension。
public void setPopupSize(int width,
int height)
setPreferredSize(new Dimension(width, height))。
width - 彈出視窗的新寬度(以像素為單位)height - 彈出視窗的新高度(以像素為單位)public void setSelected(Component sel)
sel - 要選擇的 Componentpublic boolean isBorderPainted()
setBorderPainted(boolean)public void setBorderPainted(boolean b)
b - 如果為 true,則繪製邊框。isBorderPainted()protected void paintBorder(Graphics g)
borderPainted 屬性為 true,則繪製彈出選單的邊框。
JComponent 中的 paintBorderg - Graphics 物件JComponent.paint(java.awt.Graphics),
JComponent.setBorder(javax.swing.border.Border)public Insets getMargin()
Insets 物件。protected String paramString()
JPopupMenu 的字元串表示形式。此方法僅在進行除錯的時候使用,對於各個實作,所返回字元串的內容和格式可能有所不同。返回的字元串可能為空,但不可能為 null。
JComponent 中的 paramStringJPopupMenu 的字元串表示形式。public AccessibleContext getAccessibleContext()
Accessible 中的 getAccessibleContextJComponent 中的 getAccessibleContext
public void processMouseEvent(MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
MenuElement 介面,但它沒有被實作。
MenuElement 中的 processMouseEventMenuElement.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)
public void processKeyEvent(KeyEvent e,
MenuElement[] path,
MenuSelectionManager manager)
MenuSelectionManager 的 API 處理從 MenuSelectionManager 轉發的鍵事件並更改選單選擇。
註:不必將事件轉發到子元件。此操作可以通過 MenuSelectionManager 自動完成。
MenuElement 中的 processKeyEvente - KeyEventpath - MenuElement 路徑陣列manager - MenuSelectionManagerpublic void menuSelectionChanged(boolean isIncluded)
javax.swing.MenuElement 介面。覆寫 MenuElement.menuSelectionChanged。
MenuElement 中的 menuSelectionChangedisIncluded - 如果此選單處於啟動狀態,則為 true;如果不是,則為 falseMenuElement.menuSelectionChanged(boolean)public MenuElement[] getSubElements()
MenuElement 組成的陣列,包含此選單元件的子選單。它將只返回遵守 JMenuElement 介面的項。如果彈出選單為 null,則返回空陣列。要求此方法遵守 MenuElement 介面。
MenuElement 中的 getSubElementsMenuElement 物件的陣列MenuElement.getSubElements()public Component getComponent()
JPopupMenu 元件。
MenuElement 中的 getComponentJPopupMenu 物件MenuElement.getComponent()public boolean isPopupTrigger(MouseEvent e)
JPopupMenu 的當前安裝 UI 將 MouseEvent 視為彈出選單觸發器,則返回 true。
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。