|
JavaTM 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 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。