|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JMenuItem
javax.swing.JMenu
public class JMenu
選單的該實作是一個套件含 JMenuItem 的彈出視窗,使用者選擇 JMenuBar 上的項時會顯示該 JMenuItem。除 JMenuItem 之外,JMenu 還可以包含 JSeparator。
選單本質上是帶有關聯 JPopupMenu 的按鈕。當按下“按鈕”時,就會顯示 JPopupMenu。如果“按鈕”位於 JMenuBar 上,則該選單為頂層視窗。如果“按鈕”是另一個選單項,則 JPopupMenu 就是“右拉”選單。
通過 Action 可以配置選單,並進行一定程度的控制。對選單使用 Action 有許多直接配置選單所不及的優點。有關更多資訊,請參閱支持 Action 的 Swing 元件,可以在 The Java Tutorial 中的 How
to Use Actions 一節找到更多資訊。
有關使用選單的範例和資訊,請參閱 The Java Tutorial 中的 How to Use Menus 一節。
警告:Swing 不是執行緒安全的。有關更多資訊,請參閱 Swing's Threading Policy。
警告:此類別的序列化物件與以後的 Swing 版本不相容。當前序列化支持適用於短期存儲,或適用於在運行相同 Swing 版本的應用程序之間進行 RMI(Remote Method Invocation,遠端方法調用)。從 1.4 版本開始,已在 java.beans 套件中添加了支持所有 JavaBeansTM 長期存儲的功能。請參閱 XMLEncoder。
JMenuItem,
JSeparator,
JMenuBar,
JPopupMenu| 巢狀類別摘要 | |
|---|---|
protected class |
JMenu.AccessibleJMenu
此類別實作 JMenu 類別的可存取性支持。 |
protected class |
JMenu.WinListener
觀察彈出視窗關閉的偵聽器類別。 |
| 從類別 javax.swing.JMenuItem 繼承的巢狀類別/介面 |
|---|
JMenuItem.AccessibleJMenuItem |
| 從類別 javax.swing.AbstractButton 繼承的巢狀類別/介面 |
|---|
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener |
| 從類別 javax.swing.JComponent 繼承的巢狀類別/介面 |
|---|
JComponent.AccessibleJComponent |
| 從類別 java.awt.Container 繼承的巢狀類別/介面 |
|---|
Container.AccessibleAWTContainer |
| 從類別 java.awt.Component 繼承的巢狀類別/介面 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 欄位摘要 | |
|---|---|
protected JMenu.WinListener |
popupListener
彈出選單的視窗關閉偵聽器。 |
| 從類別 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 |
| 建構子摘要 | |
|---|---|
JMenu()
建構沒有文本的新 JMenu。 |
|
JMenu(Action a)
建構一個從提供的 Action 獲取其屬性的選單。 |
|
JMenu(String s)
建構一個新 JMenu,用提供的字元串作為其文本。 |
|
JMenu(String s,
boolean b)
建構一個新 JMenu,用提供的字元串作為其文本並指定其是否為分離式 (tear-off) 選單。 |
|
| 方法摘要 | |
|---|---|
JMenuItem |
add(Action a)
創建連接到指定 Action 物件的新選單項,並將其追加到此選單的末尾。 |
Component |
add(Component c)
將某個元件追加到此選單的末尾。 |
Component |
add(Component c,
int index)
將指定元件添加到此容器的給定位置上。 |
JMenuItem |
add(JMenuItem menuItem)
將某個選單項追加到此選單的末尾。 |
JMenuItem |
add(String s)
創建具有指定文本的新選單項,並將其追加到此選單的末尾。 |
void |
addMenuListener(MenuListener l)
添加選單事件的偵聽器。 |
void |
addSeparator()
將新分隔符追加到選單的末尾。 |
void |
applyComponentOrientation(ComponentOrientation o)
設置此選單及其中包含的所有元件的 ComponentOrientation 屬性。 |
protected PropertyChangeListener |
createActionChangeListener(JMenuItem b)
返回一個正確配置的 PropertyChangeListener,它在 Action 發生更改時更新控制元件。 |
protected JMenuItem |
createActionComponent(Action a)
該處理器方法創建添加到 JMenu 的 Action 的 JMenuItem。 |
protected JMenu.WinListener |
createWinListener(JPopupMenu p)
創建彈出選單的視窗關閉偵聽器。 |
void |
doClick(int pressTime)
以程式方式執行“單擊”。 |
protected void |
fireMenuCanceled()
通知所有對此事件型別的通知感興趣的已註冊偵聽器。 |
protected void |
fireMenuDeselected()
通知所有對此事件型別的通知感興趣的已註冊偵聽器。 |
protected void |
fireMenuSelected()
通知所有對此事件型別的通知感興趣的已註冊偵聽器。 |
AccessibleContext |
getAccessibleContext()
獲取與此 JMenu 關聯的 AccessibleContext。 |
Component |
getComponent()
返回用於繪製此 MenuElement 的 java.awt.Component。 |
int |
getDelay()
返回子選單向上或向下彈出前建議的延遲(以毫秒為單位)。 |
JMenuItem |
getItem(int pos)
返回指定位置的 JMenuItem。 |
int |
getItemCount()
返回選單上的項數,包括分隔符。 |
Component |
getMenuComponent(int n)
返回位於位置 n 的元件。 |
int |
getMenuComponentCount()
返回選單上的元件數。 |
Component[] |
getMenuComponents()
返回選單子元件的 Component 陣列。 |
MenuListener[] |
getMenuListeners()
返回利用 addMenuListener() 添加到此 JMenu 的所有 MenuListener 組成的陣列。 |
JPopupMenu |
getPopupMenu()
返回與此選單關聯的彈出選單。 |
protected Point |
getPopupMenuOrigin()
計算 JMenu 的彈出選單的原點。 |
MenuElement[] |
getSubElements()
返回由 MenuElement 組成的陣列,其中包含此選單元件的子選單。 |
String |
getUIClassID()
返回呈現此元件的 L&F 類別的名稱。 |
JMenuItem |
insert(Action a,
int pos)
在給定位置插入連接到指定 Action 物件的新選單項。 |
JMenuItem |
insert(JMenuItem mi,
int pos)
在給定位置插入指定的 JMenuitem。 |
void |
insert(String s,
int pos)
在給定位置插入具有指定文本的新選單項。 |
void |
insertSeparator(int index)
在指定的位置插入分隔符。 |
boolean |
isMenuComponent(Component c)
如果在子選單層次結構中存在指定的元件,則返回 true。 |
boolean |
isPopupMenuVisible()
如果選單的彈出視窗可見,則返回 true。 |
boolean |
isSelected()
如果選單是當前選擇的(即高亮顯示的)選單,則返回 true。 |
boolean |
isTearOff()
如果此選單是分離式的,則返回 true。 |
boolean |
isTopLevelMenu()
如果選單是“頂層選單”(即選單欄的直接子級),則返回 true。 |
void |
menuSelectionChanged(boolean isIncluded)
當選單欄選擇更改為啟動或取消啟動此選單時傳遞訊息。 |
protected String |
paramString()
返回此 JMenu 的字元串表示形式。 |
protected void |
processKeyEvent(KeyEvent evt)
處理鍵擊事件,如助記符和加速器。 |
void |
remove(Component c)
從此選單移除元件 c。 |
void |
remove(int pos)
從此選單移除指定索引處的選單項。 |
void |
remove(JMenuItem item)
從此選單移除指定的選單項。 |
void |
removeAll()
從此選單移除所有選單項。 |
void |
removeMenuListener(MenuListener l)
移除選單事件的偵聽器。 |
void |
setAccelerator(KeyStroke keyStroke)
沒有為 JMenu 定義 setAccelerator。 |
void |
setComponentOrientation(ComponentOrientation o)
設置語言敏感的方向,用於排序此元件內的元素或文本。 |
void |
setDelay(int d)
設置選單的 PopupMenu 向上或向下彈出前建議的延遲。 |
void |
setMenuLocation(int x,
int y)
設置彈出元件的位置。 |
void |
setModel(ButtonModel newModel)
設置“選單按鈕”的資料模型,即使用者單擊可以打開或關閉選單的標籤。 |
void |
setPopupMenuVisible(boolean b)
設置選單彈出的可見性。 |
void |
setSelected(boolean b)
設置選單的選擇狀態。 |
void |
updateUI()
利用當前外觀的值重置 UI 屬性。 |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 從介面 javax.swing.MenuElement 繼承的方法 |
|---|
processKeyEvent, processMouseEvent |
| 欄位詳細資訊 |
|---|
protected JMenu.WinListener popupListener
JMenu.WinListener| 建構子詳細資訊 |
|---|
public JMenu()
JMenu。
public JMenu(String s)
JMenu,用提供的字元串作為其文本。
s - 選單標籤的文本public JMenu(Action a)
Action 獲取其屬性的選單。
a - Action
public JMenu(String s,
boolean b)
JMenu,用提供的字元串作為其文本並指定其是否為分離式 (tear-off) 選單。
s - 選單標籤的文本b - 選單是否是分離式的(尚未實作)| 方法詳細資訊 |
|---|
public void updateUI()
JMenuItem 中的 updateUIJComponent.updateUI()public String getUIClassID()
JMenuItem 中的 getUIClassIDJComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)public void setModel(ButtonModel newModel)
JMenuItem 中的 setModelnewModel - ButtonModelAbstractButton.getModel()public boolean isSelected()
AbstractButton 中的 isSelectedpublic void setSelected(boolean b)
AbstractButton 中的 setSelectedb - true 表示選擇(高亮顯示)選單,false 表示取消選擇選單public boolean isPopupMenuVisible()
public void setPopupMenuVisible(boolean b)
b - 一個 boolean 值,true 表示選單可見,false 表示隱藏protected Point getPopupMenuOrigin()
JMenu 的彈出選單的原點。此方法使用名為 Menu.menuPopupOffsetX、Menu.menuPopupOffsetY、Menu.submenuPopupOffsetX 和 Menu.submenuPopupOffsetY 的外觀屬性調整彈出的確切位置。
Point,該點應該用作 JMenu 的彈出選單的原點public int getDelay()
delay 屬性的策略。在大多數情況下,對於頂層選單或正在拖動的選單,不查看延遲。delay 的預設值為 0。此方法是外觀程式碼的屬性,用於管理各種 UI 實作的特質。
delay 屬性public void setDelay(int d)
PopupMenu 向上或向下彈出前建議的延遲。每個外觀 (L&F) 都可以確定它自己查看 delay 屬性的策略。在大多數情況下,對於頂層選單或正在拖動的選單,不查看延遲。此方法是外觀程式碼的屬性,用於管理各種 UI 實作的特質。
d - 要延遲的毫秒數
IllegalArgumentException - 如果 d 小於 0
public void setMenuLocation(int x,
int y)
x - 彈出選單的新位置的 x 坐標y - 彈出選單的新位置的 y 坐標public JMenuItem add(JMenuItem menuItem)
menuItem - 要添加的 JMenuitem
JMenuItempublic Component add(Component c)
Container 中的 addc - 要添加的 Component
ComponentContainer.addImpl(java.awt.Component, java.lang.Object, int),
Container.validate(),
JComponent.revalidate()
public Component add(Component c,
int index)
index 等於 -1,則將元件追加到末尾。
Container 中的 addc - 要添加的 Componentindex - 要插入元件的位置
Componentremove(javax.swing.JMenuItem),
Container.add(Component, int)public JMenuItem add(String s)
s - 要添加的選單項的字元串public JMenuItem add(Action a)
Action 物件的新選單項,並將其追加到此選單的末尾。
a - 要添加的選單項的 ActionActionprotected JMenuItem createActionComponent(Action a)
JMenu 的 Action 的 JMenuItem。
a - 要添加的選單項的 Action
Actionprotected PropertyChangeListener createActionChangeListener(JMenuItem b)
PropertyChangeListener,它在 Action 發生更改時更新控制元件。
public void addSeparator()
public void insert(String s,
int pos)
s - 要添加的選單項的文本pos - 指定要添加新選單項的位置的整數
IllegalArgumentException - 當 pos 的值 < 0 時
public JMenuItem insert(JMenuItem mi,
int pos)
JMenuitem。
mi - 要添加的 JMenuitempos - 指定要添加新 JMenuitem 的位置的整數
IllegalArgumentException - 如果 pos 的值 < 0
public JMenuItem insert(Action a,
int pos)
Action 物件的新選單項。
a - 要添加的選單項的 Action 物件pos - 指定要添加新選單項的位置的整數
IllegalArgumentException - 如果 pos 的值 < 0public void insertSeparator(int index)
index - 指定要插入選單分隔符的位置的整數
IllegalArgumentException - 如果 index 的值 < 0public JMenuItem getItem(int pos)
JMenuItem。如果位於 pos 的元件不是選單項,則返回 null。包含此方法是為了 AWT 相容性。
pos - 指定位置的整數
null
IllegalArgumentException - 如果 pos 的值 < 0public int getItemCount()
getMenuComponentCount()public boolean isTearOff()
Error - 如果調用(此方法尚未實作)public void remove(JMenuItem item)
item - 要從該選單移除的 JMenuItempublic void remove(int pos)
Container 中的 removepos - 要移除的項的位置
IllegalArgumentException - 如果 pos 的值 < 0 或者 pos 大於選單項數Container.add(java.awt.Component),
Container.validate(),
Container.getComponentCount()public void remove(Component c)
c。
Container 中的 removec - 要移除的元件Container.add(java.awt.Component),
Container.validate(),
Container.remove(int)public void removeAll()
Container 中的 removeAllContainer.add(java.awt.Component),
Container.remove(int)public int getMenuComponentCount()
public Component getMenuComponent(int n)
n 的元件。
n - 要返回的元件的位置
nullpublic Component[] getMenuComponents()
Component 陣列。注意,此操作返回彈出選單中的所有 Component,包括分隔符。
Component 陣列;如果不存在彈出選單,則返回空陣列public boolean isTopLevelMenu()
public boolean isMenuComponent(Component c)
c - 要測試的 Component
Component 存在,則返回 true;否則返回 falsepublic JPopupMenu getPopupMenu()
public void addMenuListener(MenuListener l)
l - 要添加的偵聽器public void removeMenuListener(MenuListener l)
l - 要移除的偵聽器public MenuListener[] getMenuListeners()
MenuListener 組成的陣列。
MenuListener,如果沒有添加偵聽器,則返回一個空陣列protected void fireMenuSelected()
Error - 如果存在 null 偵聽器EventListenerListprotected void fireMenuDeselected()
Error - 如果存在 null 偵聽器EventListenerListprotected void fireMenuCanceled()
Error - 如果存在 null 偵聽器EventListenerListprotected JMenu.WinListener createWinListener(JPopupMenu p)
p - JPopupMenu
JMenu.WinListenerpublic void menuSelectionChanged(boolean isIncluded)
JMenuItem.menuSelectionChanged。
MenuElement 中的 menuSelectionChangedJMenuItem 中的 menuSelectionChangedisIncluded - 如果此選單處於啟動狀態,則返回 true;如果不是,則返回 falseMenuSelectionManager.setSelectedPath(MenuElement[])public MenuElement[] getSubElements()
MenuElement 組成的陣列,其中包含此選單元件的子選單。如果彈出選單為 null,則返回空陣列。要求此方法遵守 MenuElement 介面。注意,由於 JSeparator 不遵守 MenuElement 介面,因此此陣列只包含 JMenuItem。
MenuElement 中的 getSubElementsJMenuItem 中的 getSubElementsMenuElement 物件的陣列。public Component getComponent()
MenuElement 的 java.awt.Component。返回的元件用於轉換事件並檢測某個事件是否位於選單元件中。
MenuElement 中的 getComponentJMenuItem 中的 getComponentComponentpublic void applyComponentOrientation(ComponentOrientation o)
ComponentOrientation 屬性。這包括由 getMenuComponents 返回的所有元件。
Container 中的 applyComponentOrientationo - 此選單的新元件的方向性和其中包含元件的方向性。
NullPointerException - 如果 orientation 為 null。Component.setComponentOrientation(java.awt.ComponentOrientation),
Component.getComponentOrientation()public void setComponentOrientation(ComponentOrientation o)
Component 複製的描述LayoutManager 和 Component 子類別使用此屬性來確定如何佈局並繪製元件。
在建構時,元件的方向設置為 ComponentOrientation.UNKNOWN,表示尚未顯式地指定它。UNKNOWN 方向的行為與 ComponentOrientation.LEFT_TO_RIGHT 相同。
要設置單個元件的方向,請使用此方法。要設置整個元件層次結構的方向,請使用 applyComponentOrientation。
Component 中的 setComponentOrientationComponentOrientationpublic void setAccelerator(KeyStroke keyStroke)
JMenu 定義 setAccelerator。而使用 setMnemonic 來代替。
JMenuItem 中的 setAcceleratorkeyStroke - 鍵擊組合,它調用 JMenuItem 的 actionlistener 而不必導航選單的層次結構
Error - 如果調用(沒有為 JMenu 定義此方法。使用 setMnemonic 來代替)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 void doClick(int pressTime)
AbstractButton.doClick 方法。
AbstractButton 中的 doClickpressTime - 指示按下按鈕的毫秒數protected String paramString()
JMenu 的字元串表示形式。此方法僅在進行除錯的時候使用,對於各個實作,所返回字元串的內容和格式可能有所不同。返回的字元串可能為空,但不可能為 null。
JMenuItem 中的 paramStringpublic AccessibleContext getAccessibleContext()
Accessible 中的 getAccessibleContextJMenuItem 中的 getAccessibleContext
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。