Class JMenu
- All Implemented Interfaces:
- ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
JMenuItems that
is displayed when the user selects an item on the JMenuBar.
In addition to JMenuItems, a JMenu can
also contain JSeparators.
In essence, a menu is a button with an associated JPopupMenu.
When the "button" is pressed, the JPopupMenu appears. If the
"button" is on the JMenuBar, the menu is a top-level window.
If the "button" is another menu item, then the JPopupMenu is
"pull-right" menu.
Menus can be configured, and to some degree controlled, by
Actions.  Using an
Action with a menu has many benefits beyond directly
configuring a menu.  Refer to 
Swing Components Supporting Action for more
details, and you can find more information in How
to Use Actions, a section in The Java Tutorial.
For information and examples of using menus see How to Use Menus, a section in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing.  As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see XMLEncoder.
- Since:
- 1.2
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theJMenuclass.protected classA listener class that watches for a popup window closing.Nested classes/interfaces declared in class JMenuItemJMenuItem.AccessibleJMenuItemNested classes/interfaces declared in class AbstractButtonAbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerNested classes/interfaces declared in class JComponentJComponent.AccessibleJComponentNested classes/interfaces declared in class ContainerContainer.AccessibleAWTContainerNested classes/interfaces declared in class ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected JMenu.WinListenerThe window-closing listener for the popup.Fields declared in class AbstractButtonactionListener, 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 JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields declared in interface SwingConstantsBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
- 
Constructor SummaryConstructorsConstructorDescriptionJMenu()Constructs a newJMenuwith no text.Constructs a newJMenuwith the supplied string as its text.Constructs a newJMenuwith the supplied string as its text and specified as a tear-off menu or not.Constructs a menu whose properties are taken from theActionsupplied.
- 
Method SummaryModifier and TypeMethodDescriptionAppends a component to the end of this menu.Adds the specified component to this container at the given position.Creates a new menu item with the specified text and appends it to the end of this menu.Creates a new menu item attached to the specifiedActionobject and appends it to the end of this menu.Appends a menu item to the end of this menu.voidAdds a listener for menu events.voidAppends a new separator to the end of the menu.voidSets theComponentOrientationproperty of this menu and all components contained within it.protected PropertyChangeListenerReturns a properly configuredPropertyChangeListenerwhich updates the control as changes to theActionoccur.protected JMenuItemFactory method which creates theJMenuItemforActions added to theJMenu.protected JMenu.WinListenerCreates a window-closing listener for the popup.voiddoClick(int pressTime) Programmatically performs a "click".protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.Gets the AccessibleContext associated with this JMenu.Returns thejava.awt.Componentused to paint thisMenuElement.intgetDelay()Returns the suggested delay, in milliseconds, before submenus are popped up or down.getItem(int pos) Returns theJMenuItemat the specified position.intReturns the number of items on the menu, including separators.getMenuComponent(int n) Returns the component at positionn.intReturns the number of components on the menu.Returns an array ofComponents of the menu's subcomponents.Returns an array of all theMenuListeners added to this JMenu with addMenuListener().Returns the popupmenu associated with this menu.protected PointComputes the origin for theJMenu's popup menu.Returns an array ofMenuElements containing the submenu for this menu component.Returns the name of the L&F class that renders this component.voidInserts a new menu item with the specified text at a given position.Inserts a new menu item attached to the specifiedActionobject at a given position.Inserts the specifiedJMenuitemat a given position.voidinsertSeparator(int index) Inserts a separator at the specified position.booleanReturns true if the specified component exists in the submenu hierarchy.booleanReturns true if the menu's popup window is visible.booleanReturns true if the menu is currently selected (highlighted).booleanReturns true if the menu can be torn off.booleanReturns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.voidmenuSelectionChanged(boolean isIncluded) Messaged when the menubar selection changes to activate or deactivate this menu.protected StringReturns a string representation of thisJMenu.protected voidprocessKeyEvent(KeyEvent evt) Processes key stroke events such as mnemonics and accelerators.voidremove(int pos) Removes the menu item at the specified index from this menu.voidRemoves the componentcfrom this menu.voidRemoves the specified menu item from this menu.voidRemoves all menu items from this menu.voidRemoves a listener for menu events.voidsetAccelerator(KeyStroke keyStroke) setAcceleratoris not defined forJMenu.voidSets the orientation for this menu and its associated popup menu determined by theComponentOrientationargument.voidsetDelay(int d) Sets the suggested delay before the menu'sPopupMenuis popped up or down.voidsetMenuLocation(int x, int y) Sets the location of the popup component.voidsetModel(ButtonModel newModel) Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.voidsetPopupMenuVisible(boolean b) Sets the visibility of the menu's popup.voidsetSelected(boolean b) Sets the selection status of the menu.voidupdateUI()Resets the UI property with a value from the current look and feel.Methods declared in class JMenuItemactionPropertyChanged, 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 AbstractButtonaddActionListener, 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 JComponentaddAncestorListener, 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 Containeradd, 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 Componentaction, 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 Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface MenuElementprocessKeyEvent, processMouseEvent
- 
Field Details- 
popupListener
 
- 
- 
Constructor Details- 
JMenupublic JMenu()Constructs a newJMenuwith no text.
- 
JMenuConstructs a newJMenuwith the supplied string as its text.- Parameters:
- s- the text for the menu label
 
- 
JMenuConstructs a menu whose properties are taken from theActionsupplied.- Parameters:
- a- an- Action
- Since:
- 1.3
 
- 
JMenuConstructs a newJMenuwith the supplied string as its text and specified as a tear-off menu or not.- Parameters:
- s- the text for the menu label
- b- can the menu be torn off (not yet implemented)
 
 
- 
- 
Method Details- 
updateUI
- 
getUIClassIDReturns the name of the L&F class that renders this component.- Overrides:
- getUIClassIDin class- JMenuItem
- Returns:
- the string "MenuUI"
- See Also:
 
- 
setModelSets the data model for the "menu button" -- the label that the user clicks to open or close the menu.- Overrides:
- setModelin class- AbstractButton
- Parameters:
- newModel- the- ButtonModel
- See Also:
 
- 
isSelectedpublic boolean isSelected()Returns true if the menu is currently selected (highlighted).- Overrides:
- isSelectedin class- AbstractButton
- Returns:
- true if the menu is selected, else false
 
- 
setSelected@BeanProperty(expert=true, hidden=true, description="When the menu is selected, its popup child is shown.") public void setSelected(boolean b) Sets the selection status of the menu.- Overrides:
- setSelectedin class- AbstractButton
- Parameters:
- b- true to select (highlight) the menu; false to de-select the menu
 
- 
isPopupMenuVisiblepublic boolean isPopupMenuVisible()Returns true if the menu's popup window is visible.- Returns:
- true if the menu is visible, else false
 
- 
setPopupMenuVisible@BeanProperty(bound=false, expert=true, hidden=true, description="The popup menu's visibility") public void setPopupMenuVisible(boolean b) Sets the visibility of the menu's popup. If the menu is not enabled, this method will have no effect.- Parameters:
- b- a boolean value -- true to make the menu visible, false to hide it
 
- 
getPopupMenuOriginComputes the origin for theJMenu's popup menu. This method uses Look and Feel properties namedMenu.menuPopupOffsetX,Menu.menuPopupOffsetY,Menu.submenuPopupOffsetX, andMenu.submenuPopupOffsetYto adjust the exact location of popup.- Returns:
- a Pointin the coordinate space of the menu which should be used as the origin of theJMenu's popup menu
- Since:
- 1.3
 
- 
getDelaypublic int getDelay()Returns the suggested delay, in milliseconds, before submenus are popped up or down. Each look and feel (L&F) may determine its own policy for observing thedelayproperty. In most cases, the delay is not observed for top level menus or while dragging. The default fordelayis 0. This method is a property of the look and feel code and is used to manage the idiosyncrasies of the various UI implementations.- Returns:
- the delayproperty
 
- 
setDelay@BeanProperty(bound=false, expert=true, description="The delay between menu selection and making the popup menu visible") public void setDelay(int d) Sets the suggested delay before the menu'sPopupMenuis popped up or down. Each look and feel (L&F) may determine it's own policy for observing the delay property. In most cases, the delay is not observed for top level menus or while dragging. This method is a property of the look and feel code and is used to manage the idiosyncrasies of the various UI implementations.- Parameters:
- d- the number of milliseconds to delay
- Throws:
- IllegalArgumentException- if- dis less than 0
 
- 
setMenuLocationpublic void setMenuLocation(int x, int y) Sets the location of the popup component.- Parameters:
- x- the x coordinate of the popup's new position
- y- the y coordinate of the popup's new position
 
- 
add
- 
add
- 
addAdds the specified component to this container at the given position. Ifindexequals -1, the component will be appended to the end.
- 
add
- 
add
- 
createActionComponent
- 
createActionChangeListenerReturns a properly configuredPropertyChangeListenerwhich updates the control as changes to theActionoccur.- Parameters:
- b- a menu item for which to create a- PropertyChangeListener
- Returns:
- a PropertyChangeListenerforb
 
- 
addSeparatorpublic void addSeparator()Appends a new separator to the end of the menu.
- 
insertInserts a new menu item with the specified text at a given position.- Parameters:
- s- the text for the menu item to add
- pos- an integer specifying the position at which to add the new menu item
- Throws:
- IllegalArgumentException- when the value of- pos< 0
 
- 
insertInserts the specifiedJMenuitemat a given position.- Parameters:
- mi- the- JMenuitemto add
- pos- an integer specifying the position at which to add the new- JMenuitem
- Returns:
- the new menu item
- Throws:
- IllegalArgumentException- if the value of- pos< 0
 
- 
insertInserts a new menu item attached to the specifiedActionobject at a given position.- Parameters:
- a- the- Actionobject for the menu item to add
- pos- an integer specifying the position at which to add the new menu item
- Returns:
- the new menu item
- Throws:
- IllegalArgumentException- if the value of- pos< 0
 
- 
insertSeparatorpublic void insertSeparator(int index) Inserts a separator at the specified position.- Parameters:
- index- an integer specifying the position at which to insert the menu separator
- Throws:
- IllegalArgumentException- if the value of- index< 0
 
- 
getItemReturns theJMenuItemat the specified position. If the component atposis not a menu item,nullis returned. This method is included for AWT compatibility.- Parameters:
- pos- an integer specifying the position
- Returns:
- the menu item at the specified position; or nullif the item as the specified position is not a menu item
- Throws:
- IllegalArgumentException- if the value of- pos< 0
 
- 
getItemCountReturns the number of items on the menu, including separators. This method is included for AWT compatibility.- Returns:
- an integer equal to the number of items on the menu
- See Also:
 
- 
isTearOffReturns true if the menu can be torn off. This method is not yet implemented.- Returns:
- true if the menu can be torn off, else false
- Throws:
- Error- if invoked -- this method is not yet implemented
 
- 
removeRemoves the specified menu item from this menu. If there is no popup menu, this method will have no effect.- Parameters:
- item- the- JMenuItemto be removed from the menu
 
- 
removepublic void remove(int pos) Removes the menu item at the specified index from this menu.- Overrides:
- removein class- Container
- Parameters:
- pos- the position of the item to be removed
- Throws:
- IllegalArgumentException- if the value of- pos< 0, or if- posis greater than the number of menu items
- See Also:
 
- 
remove
- 
removeAll
- 
getMenuComponentCountReturns the number of components on the menu.- Returns:
- an integer containing the number of components on the menu
 
- 
getMenuComponentReturns the component at positionn.- Parameters:
- n- the position of the component to be returned
- Returns:
- the component requested, or nullif there is no popup menu
 
- 
getMenuComponentsReturns an array ofComponents of the menu's subcomponents. Note that this returns allComponents in the popup menu, including separators.- Returns:
- an array of Components or an empty array if there is no popup menu
 
- 
isTopLevelMenuReturns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.- Returns:
- true if the menu is activated from the menu bar; false if the menu is activated from a menu item on another menu
 
- 
isMenuComponentReturns true if the specified component exists in the submenu hierarchy.- Parameters:
- c- the- Componentto be tested
- Returns:
- true if the Componentexists, false otherwise
 
- 
getPopupMenuReturns the popupmenu associated with this menu. If there is no popupmenu, it will create one.- Returns:
- the JPopupMenuassociated with this menu
 
- 
addMenuListenerAdds a listener for menu events.- Parameters:
- l- the listener to be added
 
- 
removeMenuListenerRemoves a listener for menu events.- Parameters:
- l- the listener to be removed
 
- 
getMenuListenersReturns an array of all theMenuListeners added to this JMenu with addMenuListener().- Returns:
- all of the MenuListeners added or an empty array if no listeners have been added
- Since:
- 1.4
 
- 
fireMenuSelectedprotected void fireMenuSelected()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
- Error- if there is a- nulllistener
- See Also:
 
- 
fireMenuDeselectedprotected void fireMenuDeselected()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
- Error- if there is a- nulllistener
- See Also:
 
- 
fireMenuCanceledprotected void fireMenuCanceled()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
- Error- if there is a- nulllistener
- See Also:
 
- 
createWinListenerCreates a window-closing listener for the popup.- Parameters:
- p- the- JPopupMenu
- Returns:
- the new window-closing listener
- See Also:
 
- 
getSubElementsReturns an array ofMenuElements containing the submenu for this menu component. If popup menu isnullreturns an empty array. This method is required to conform to theMenuElementinterface. Note that sinceJSeparators do not conform to theMenuElementinterface, this array will only containJMenuItems.- Specified by:
- getSubElementsin interface- MenuElement
- Overrides:
- getSubElementsin class- JMenuItem
- Returns:
- an array of MenuElementobjects
 
- 
getComponentReturns thejava.awt.Componentused to paint thisMenuElement. The returned component is used to convert events and detect if an event is inside a menu component.- Specified by:
- getComponentin interface- MenuElement
- Overrides:
- getComponentin class- JMenuItem
- Returns:
- the Componentthat paints this menu item
 
- 
applyComponentOrientationSets theComponentOrientationproperty of this menu and all components contained within it. This includes all components returned bygetMenuComponents.- Overrides:
- applyComponentOrientationin class- Container
- Parameters:
- o- the new component orientation of this menu and the components contained within it.
- Throws:
- NullPointerException- if- orientationis null.
- Since:
- 1.4
- See Also:
 
- 
setComponentOrientationSets the orientation for this menu and its associated popup menu determined by theComponentOrientationargument.- Overrides:
- setComponentOrientationin class- Component
- Parameters:
- o- the new orientation for this menu and its associated popup menu.
- See Also:
 
- 
setAcceleratorsetAcceleratoris not defined forJMenu. UsesetMnemonicinstead.- Overrides:
- setAcceleratorin class- JMenuItem
- Parameters:
- keyStroke- the keystroke combination which will invoke the- JMenuItem's actionlisteners without navigating the menu hierarchy
- Throws:
- Error- if invoked -- this method is not defined for JMenu. Use- setMnemonicinstead
 
- 
processKeyEventProcesses key stroke events such as mnemonics and accelerators.- Overrides:
- processKeyEventin class- JComponent
- Parameters:
- evt- the key event to be processed
- See Also:
 
- 
doClickpublic void doClick(int pressTime) Programmatically performs a "click". This overrides the methodAbstractButton.doClickin order to make the menu pop up.- Overrides:
- doClickin class- AbstractButton
- Parameters:
- pressTime- indicates the number of milliseconds the button was pressed for
 
- 
paramStringReturns a string representation of thisJMenu. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not benull.- Overrides:
- paramStringin class- JMenuItem
- Returns:
- a string representation of this JMenu.
 
- 
getAccessibleContextGets the AccessibleContext associated with this JMenu. For JMenus, the AccessibleContext takes the form of an AccessibleJMenu. A new AccessibleJMenu instance is created if necessary.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- JMenuItem
- Returns:
- an AccessibleJMenu that serves as the AccessibleContext of this JMenu
 
 
-