- 所有已实现的接口:
-
ImageObserver,ItemSelectable,MenuContainer,Serializable,Accessible,MenuElement,SwingConstants
@JavaBean(description="A popup window containing menu items displayed in a menu bar.") public class JMenu extends JMenuItem implements Accessible, MenuElement
菜单的实现--一个弹出窗口,包含
JMenuItem,当用户在JMenuBar上选择项目时显示。除了JMenuItem外,JMenu还可以包含JSeparator。
本质上,菜单是一个带有关联JPopupMenu的按钮。当按下“按钮”时,JPopupMenu会出现。如果“按钮”在JMenuBar上,菜单是一个顶层窗口。如果“按钮”是另一个菜单项,则JPopupMenu是“向右拉出”菜单。
菜单可以通过Action进行配置和控制。使用Action与菜单有许多好处,超出直接配置菜单。有关更多详细信息,请参阅支持Action的Swing组件,您可以在如何使用Actions中找到更多信息,这是The Java Tutorial中的一节。
有关使用菜单的信息和示例,请参阅The Java Tutorial中的如何使用菜单部分。
警告: Swing不是线程安全的。有关更多信息,请参阅Swing的线程策略。
警告: 该类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间进行RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans包中。请参阅XMLEncoder。
- 自1.2版本起:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class该类实现了JMenu类的辅助功能支持。protected class监视弹出窗口关闭的监听器类。Nested classes/interfaces declared in class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItemNested classes/interfaces declared in class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerNested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsFields declared in class 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_PROPERTYFields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields declared in interface 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription将组件附加到此菜单的末尾。将指定的组件添加到给定位置的容器中。创建一个具有指定文本的新菜单项,并将其附加到此菜单的末尾。创建一个附加到指定Action对象的新菜单项,并将其附加到此菜单的末尾。将菜单项附加到此菜单的末尾。void为菜单事件添加监听器。void在菜单的末尾添加一个新的分隔符。void设置此菜单及其所有包含的组件的ComponentOrientation属性。protected PropertyChangeListener返回一个正确配置的PropertyChangeListener,当Action发生更改时更新控件。protected JMenuItem为添加到JMenu的Action创建JMenuItem的工厂方法。protected JMenu.WinListener为弹出窗口创建一个窗口关闭监听器。voiddoClick(int pressTime) 以编程方式执行“点击”。protected void通知所有已注册对此事件类型感兴趣的监听器。protected void通知所有已注册对此事件类型感兴趣的监听器。protected void通知所有已注册对此事件类型感兴趣的监听器。获取与此JMenu关联的AccessibleContext。返回用于绘制此MenuElement的java.awt.Component。intgetDelay()返回弹出子菜单之前或之后建议的延迟时间(以毫秒为单位)。getItem(int pos) 返回指定位置的JMenuItem。int返回菜单上的项目数,包括分隔符。getMenuComponent(int n) 返回位置n处的组件。int返回菜单上组件的数量。返回菜单子组件的Component数组。返回添加到此JMenu的所有MenuListener的数组。返回与此菜单关联的弹出菜单。protected Point计算JMenu的弹出菜单的起点。返回包含此菜单组件子菜单的MenuElement数组。返回呈现此组件的L&F类的名称。void在给定位置插入具有指定文本的新菜单项。在给定位置插入附加到指定Action对象的新菜单项。在给定位置插入指定的JMenuitem。voidinsertSeparator(int index) 在指定位置插入分隔符。boolean如果指定的组件存在于子菜单层次结构中,则返回true。boolean如果菜单的弹出窗口可见,则返回true。boolean如果菜单当前被选中(高亮显示),则返回true。boolean如果菜单可以拆分,则返回true。boolean如果菜单是“顶级菜单”,即它是菜单栏的直接子菜单,则返回true。voidmenuSelectionChanged(boolean isIncluded) 当菜单栏选择更改以激活或停用此菜单时发送消息。protected String返回此JMenu的字符串表示形式。protected voidprocessKeyEvent(KeyEvent evt) 处理键盘按键事件,如助记键和加速键。voidremove(int pos) 从此菜单中删除指定索引处的菜单项。void从此菜单中删除组件c。void从此菜单中删除指定的菜单项。void从此菜单中删除所有菜单项。void删除菜单事件的监听器。voidsetAccelerator(KeyStroke keyStroke) JMenu不定义setAccelerator。void设置此菜单及其关联的弹出菜单的方向,由ComponentOrientation参数确定。voidsetDelay(int d) 设置菜单的PopupMenu弹出或关闭前的建议延迟时间。voidsetMenuLocation(int x, int y) 设置弹出组件的位置。voidsetModel(ButtonModel newModel) 设置“菜单按钮”的数据模型--用户单击以打开或关闭菜单的标签。voidsetPopupMenuVisible(boolean b) 设置菜单的弹出窗口的可见性。voidsetSelected(boolean b) 设置菜单的选择状态。voidupdateUI()重置当前外观和感觉的UI属性。Methods declared in class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUIMethods declared in class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPositionMethods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods declared in class java.awt.Container
add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTreeMethods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface javax.swing.MenuElement
processKeyEvent, processMouseEvent
-
Field Details
-
popupListener
弹出窗口的关闭监听器。- 参见:
-
-
Constructor Details
-
JMenu
public JMenu()构造一个没有文本的新JMenu。 -
JMenu
用提供的字符串作为其文本构造一个新的JMenu。- 参数:
-
s- 菜单标签的文本
-
JMenu
构造一个从提供的Action获取属性的菜单。- 参数:
-
a- 一个Action - 自1.3版本起:
-
JMenu
用提供的字符串作为其文本构造一个新的JMenu,并指定为可拆分菜单或非拆分菜单。- 参数:
-
s- 菜单标签的文本 -
b- 菜单是否可拆分(尚未实现)
-
-
Method Details
-
updateUI
public void updateUI()重置当前外观和感觉的UI属性。 -
getUIClassID
返回呈现此组件的L&F类的名称。- 覆盖:
-
getUIClassID在类JMenuItem中 - 返回:
- 字符串“MenuUI”
- 参见:
-
setModel
设置“菜单按钮”的数据模型--用户单击以打开或关闭菜单的标签。- 覆盖:
-
setModel在类AbstractButton - 参数:
-
newModel-ButtonModel - 参见:
-
isSelected
public boolean isSelected()如果菜单当前被选中(高亮),则返回true。- 覆盖:
-
isSelected在类AbstractButton - 返回:
- 如果菜单被选中,则返回true,否则返回false
-
setSelected
@BeanProperty(expert=true, hidden=true, description="When the menu is selected, its popup child is shown.") public void setSelected(boolean b) 设置菜单的选择状态。- 覆盖:
-
setSelected在类AbstractButton - 参数:
-
b- true表示选择(高亮)菜单;false表示取消选择菜单
-
isPopupMenuVisible
public boolean isPopupMenuVisible()如果菜单的弹出窗口当前可见,则返回true。- 返回:
- 如果菜单可见,则返回true,否则返回false
-
setPopupMenuVisible
@BeanProperty(bound=false, expert=true, hidden=true, description="The popup menu\'s visibility") public void setPopupMenuVisible(boolean b) 设置菜单的弹出窗口的可见性。如果菜单未启用,则此方法不会产生任何效果。- 参数:
-
b- 一个布尔值 -- true表示使菜单可见,false表示隐藏菜单
-
getPopupMenuOrigin
计算JMenu的弹出菜单的起点。此方法使用名为Menu.menuPopupOffsetX、Menu.menuPopupOffsetY、Menu.submenuPopupOffsetX和Menu.submenuPopupOffsetY的外观属性来调整弹出菜单的确切位置。- 返回:
-
应在
JMenu的坐标空间中用作JMenu的弹出菜单起点的Point - 自:
- 1.3
-
getDelay
public int getDelay()返回建议的延迟时间(以毫秒为单位),用于弹出或关闭子菜单。每个外观和感觉(L&F)可能会确定其自己的策略来观察delay属性。在大多数情况下,顶级菜单或拖动时不会观察延迟。默认的delay为0。此方法是外观代码的属性,用于管理各种UI实现的特殊性。- 返回:
-
delay属性
-
setDelay
@BeanProperty(bound=false, expert=true, description="The delay between menu selection and making the popup menu visible") public void setDelay(int d) 设置菜单的PopupMenu弹出或关闭前的建议延迟。每个外观和感觉(L&F)可能会确定其自己的策略来观察延迟属性。在大多数情况下,顶级菜单或拖动时不会观察延迟。此方法是外观代码的属性,用于管理各种UI实现的特殊性。- 参数:
-
d- 延迟的毫秒数 - 抛出:
-
IllegalArgumentException- 如果d小于0
-
setMenuLocation
public void setMenuLocation(int x, int y) 设置弹出组件的位置。- 参数:
-
x- 弹出位置的x坐标 -
y- 弹出位置的y坐标
-
add
将菜单项附加到此菜单的末尾。返回添加的菜单项。- 参数:
-
menuItem- 要添加的JMenuitem - 返回:
-
添加的
JMenuItem
-
add
将组件附加到此菜单的末尾。返回添加的组件。 -
add
将指定的组件添加到此容器的给定位置。如果index等于-1,则该组件将附加到末尾。 -
add
创建具有指定文本的新菜单项,并将其附加到此菜单的末尾。- 参数:
-
s- 要添加的菜单项的文本 - 返回:
-
新的
JMenuItem
-
add
创建附加到指定Action对象的新菜单项,并将其附加到此菜单的末尾。- 参数:
-
a- 要添加的菜单项的Action - 返回:
-
新的
JMenuItem - 参见:
-
createActionComponent
工厂方法,为添加到JMenu的Action创建JMenuItem。- 参数:
-
a- 要添加的菜单项的Action - 返回:
- 新的菜单项
- 自:
- 1.3
- 参见:
-
createActionChangeListener
返回一个经过适当配置的PropertyChangeListener,当Action发生更改时更新控件。- 参数:
-
b- 要为其创建PropertyChangeListener的菜单项 - 返回:
-
用于
b的PropertyChangeListener
-
addSeparator
public void addSeparator()在菜单的末尾添加一个新的分隔符。 -
insert
在给定位置插入具有指定文本的新菜单项。- 参数:
-
s- 要添加的菜单项的文本 -
pos- 指定要添加新菜单项的位置的整数 - 抛出:
-
IllegalArgumentException- 当pos的值小于0时
-
insert
在给定位置插入指定的JMenuitem。- 参数:
-
mi- 要添加的JMenuitem -
pos- 指定要添加新JMenuitem的位置的整数 - 返回:
- 新的菜单项
- 抛出:
-
IllegalArgumentException- 如果pos的值小于0
-
insert
在给定位置插入附加到指定Action对象的新菜单项。- 参数:
-
a- 要添加的菜单项的Action对象 -
pos- 指定要添加新菜单项的位置的整数 - 返回:
- 新的菜单项
- 抛出:
-
IllegalArgumentException- 如果pos的值小于0
-
insertSeparator
public void insertSeparator(int index) 在指定位置插入一个分隔符。- 参数:
-
index- 指定要插入菜单分隔符的位置的整数 - 抛出:
-
IllegalArgumentException- 如果index的值小于0
-
getItem
返回指定位置的JMenuItem。如果pos处的组件不是菜单项,则返回null。此方法包含为了AWT兼容性而包含的。- 参数:
-
pos- 指定位置的整数 - 返回:
-
指定位置的菜单项;如果指定位置的项目不是菜单项,则返回
null - 抛出:
-
IllegalArgumentException- 如果pos的值小于0
-
getItemCount
返回菜单上的项目数,包括分隔符。此方法包含为了AWT兼容性而包含的。- 返回:
- 等于菜单上项目数的整数
- 参见:
-
isTearOff
如果菜单可以被拆分,则返回true。此方法尚未实现。- 返回值:
- 如果菜单可以被拆分,则为true,否则为false
- 抛出:
-
Error- 如果调用 -- 此方法尚未实现
-
remove
从此菜单中移除指定的菜单项。如果没有弹出菜单,则此方法不会产生任何效果。- 参数:
-
item- 要从菜单中移除的JMenuItem
-
remove
public void remove(int pos) 从此菜单中移除指定索引处的菜单项。- 覆盖:
-
remove在类Container - 参数:
-
pos- 要移除的项目的位置 - 抛出:
-
IllegalArgumentException- 如果pos的值小于0,或者如果pos大于菜单项的数量 - 参见:
-
remove
从此菜单中移除组件c。 -
removeAll
public void removeAll()从此菜单中移除所有菜单项。 -
getMenuComponentCount
返回菜单上组件的数量。- 返回值:
- 包含菜单上组件数量的整数
-
getMenuComponent
返回位置为n的组件。- 参数:
-
n- 要返回的组件的位置 - 返回值:
-
请求的组件,如果没有弹出菜单则返回
null
-
getMenuComponents
返回菜单子组件的Component数组。请注意,这将返回弹出菜单中的所有Component,包括分隔符。- 返回值:
-
一个
Component数组,如果没有弹出菜单则返回空数组
-
isTopLevelMenu
如果菜单是“顶级菜单”,即它是菜单栏的直接子菜单,则返回true。- 返回值:
- 如果菜单是从菜单栏激活的,则为true;如果菜单是从另一个菜单上的菜单项激活的,则为false
-
isMenuComponent
如果指定的组件存在于子菜单层次结构中,则返回true。- 参数:
-
c- 要测试的Component - 返回值:
-
如果
Component存在,则为true,否则为false
-
getPopupMenu
返回与此菜单关联的弹出菜单。如果没有弹出菜单,则将创建一个。- 返回值:
-
与此菜单关联的
JPopupMenu
-
addMenuListener
为菜单事件添加监听器。- 参数:
-
l- 要添加的监听器
-
removeMenuListener
移除菜单事件的监听器。- 参数:
-
l- 要移除的监听器
-
getMenuListeners
返回添加到此JMenu中的所有MenuListener的数组。- 返回值:
-
所有已添加的
MenuListener数组,如果没有添加监听器则返回空数组 - 自1.4起:
- 1.4
-
fireMenuSelected
protected void fireMenuSelected()通知所有已注册对此事件类型感兴趣的监听器。事件实例是延迟创建的。- 抛出:
-
Error- 如果存在null监听器 - 参见:
-
fireMenuDeselected
protected void fireMenuDeselected()通知所有已注册对此事件类型感兴趣的监听器。事件实例是延迟创建的。- 抛出:
-
Error- 如果存在null监听器 - 参见:
-
fireMenuCanceled
protected void fireMenuCanceled()通知所有已注册对此事件类型感兴趣的监听器。事件实例是延迟创建的。- 抛出:
-
Error- 如果存在null监听器 - 参见:
-
createWinListener
为弹出菜单创建一个窗口关闭监听器。- 参数:
-
p-JPopupMenu - 返回值:
- 新的窗口关闭监听器
- 参见:
-
getSubElements
返回包含此菜单组件子菜单的MenuElement数组。如果弹出菜单为null,则返回一个空数组。此方法需要符合MenuElement接口。请注意,由于JSeparator不符合MenuElement接口,因此此数组将只包含JMenuItem。- 指定者:
-
getSubElements在接口MenuElement - 覆盖:
-
getSubElements在类JMenuItem - 返回值:
-
一个
MenuElement对象数组
-
getComponent
返回用于绘制此MenuElement的java.awt.Component。返回的组件用于转换事件并检测事件是否在菜单组件内部。- 指定者:
-
getComponent在接口MenuElement - 覆盖:
-
getComponent在类JMenuItem - 返回值:
-
绘制此菜单项的
Component
-
applyComponentOrientation
设置此菜单及其中包含的所有组件的ComponentOrientation属性。这包括getMenuComponents返回的所有组件。- 覆盖:
-
applyComponentOrientation在类Container中 - 参数:
-
o- 此菜单及其中包含的组件的新组件方向。 - 抛出:
-
NullPointerException- 如果orientation为null。 - 自:
- 1.4
- 参见:
-
setComponentOrientation
设置此菜单及其关联弹出菜单的方向,由ComponentOrientation参数确定。- 覆盖:
-
setComponentOrientation在类Component中 - 参数:
-
o- 此菜单及其关联弹出菜单的新方向。 - 参见:
-
setAccelerator
setAccelerator未为JMenu定义。请改用setMnemonic。- 覆盖:
-
setAccelerator在类JMenuItem中 - 参数:
-
keyStroke- 将调用JMenuItem的动作监听器而不导航菜单层次结构的按键组合 - 抛出:
-
Error- 如果调用--此方法未为JMenu定义。请改用setMnemonic
-
processKeyEvent
处理诸如助记键和加速键等键事件。- 覆盖:
-
processKeyEvent在类JComponent中 - 参数:
-
evt- 要处理的键事件 - 参见:
-
doClick
public void doClick(int pressTime) 以编程方式执行“点击”。这覆盖了方法AbstractButton.doClick,以使菜单弹出。- 覆盖:
-
doClick在类AbstractButton中 - 参数:
-
pressTime- 按钮按下的毫秒数
-
paramString
返回此JMenu的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null。- 覆盖:
-
paramString在类JMenuItem中 - 返回:
- 此JMenu的字符串表示形式。
-
getAccessibleContext
获取与此JMenu关联的AccessibleContext。对于JMenus,AccessibleContext采用AccessibleJMenu的形式。如有必要,将创建一个新的AccessibleJMenu实例。- 指定者:
-
getAccessibleContext在接口Accessible中 - 覆盖:
-
getAccessibleContext在类JMenuItem中 - 返回:
- 作为此JMenu的AccessibleContext的AccessibleJMenu
-