| java.lang.Object | ||||||
| ↳ | java.awt.Component | |||||
| ↳ | java.awt.Container | |||||
| ↳ | javax.swing.JComponent | |||||
| ↳ | javax.swing.AbstractButton | |||||
| ↳ | javax.swing.JMenuItem | |||||
| ↳ | javax.swing.JMenu | |||||
An implementation of a menu -- a popup window containing
 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 JavaBeansTM
 has been added to the java.beans package.
 Please see XMLEncoder.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| JMenu.AccessibleJMenu | This class implements accessibility support for the
 JMenu class.  | 
    ||||||||||
| JMenu.WinListener | A listener class that watches for a popup window closing. | ||||||||||
| 
  [Expand]
   Inherited Constants  | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
   From class
javax.swing.AbstractButton
 | |||||||||||
   From class
javax.swing.JComponent
 | |||||||||||
   From class
java.awt.Component
 | |||||||||||
   From interface
java.awt.image.ImageObserver
 | |||||||||||
   From interface
javax.swing.SwingConstants
 | |||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| popupListener | The window-closing listener for the popup. | ||||||||||
| 
  [Expand]
   Inherited Fields  | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
   From class
javax.swing.AbstractButton
 | |||||||||||
   From class
javax.swing.JComponent
 | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new  
  
  JMenu with no text. | |||||||||||
Constructs a new  
  
  JMenu with the supplied string
 as its text. | |||||||||||
Constructs a menu whose properties are taken from the
  
  
  Action supplied. | |||||||||||
Constructs a new  
  
  JMenu with the supplied string as
 its text and specified as a tear-off menu or not. | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified component to this container at the given
 position. 
  
   | |||||||||||
Appends a menu item to the end of this menu. 
  
   | |||||||||||
Appends a component to the end of this menu. 
  
   | |||||||||||
Creates a new menu item attached to the specified
  
  
  Action object and appends it to the end of this menu. | |||||||||||
Creates a new menu item with the specified text and appends
 it to the end of this menu. 
  
   | |||||||||||
Adds a listener for menu events. 
  
   | |||||||||||
Appends a new separator to the end of the menu. 
  
   | |||||||||||
Sets the  
  
  ComponentOrientation property of this menu
 and all components contained within it. | |||||||||||
Programmatically performs a "click". 
  
   | |||||||||||
Gets the AccessibleContext associated with this JMenu. 
  
   | |||||||||||
Returns the  
  
  java.awt.Component used to
 paint this MenuElement. | |||||||||||
Returns the suggested delay, in milliseconds, before submenus
 are popped up or down. 
  
   | |||||||||||
Returns the  
  
  JMenuItem at the specified position. | |||||||||||
Returns the number of items on the menu, including separators. 
  
   | |||||||||||
Returns the component at position  
  
  n. | |||||||||||
Returns the number of components on the menu. 
  
   | |||||||||||
Returns an array of  
  
  Components of the menu's
 subcomponents. | |||||||||||
Returns an array of all the  
  
  MenuListeners added
 to this JMenu with addMenuListener(). | |||||||||||
Returns the popupmenu associated with this menu. 
  
   | |||||||||||
Returns an array of  
  
  MenuElements containing the submenu
 for this menu component. | |||||||||||
Returns the name of the L&F class that renders this component. 
  
   | |||||||||||
Inserts a new menu item attached to the specified  
  
  Action
 object at a given position. | |||||||||||
Inserts a new menu item with the specified text at a
 given position. 
  
   | |||||||||||
Inserts the specified  
  
  JMenuitem at a given position. | |||||||||||
Inserts a separator at the specified position. 
  
   | |||||||||||
Returns true if the specified component exists in the
 submenu hierarchy. 
  
   | |||||||||||
Returns true if the menu's popup window is visible. 
  
   | |||||||||||
Returns true if the menu is currently selected (highlighted). 
  
   | |||||||||||
Returns true if the menu can be torn off. 
  
   | |||||||||||
Returns true if the menu is a 'top-level menu', that is, if it is
 the direct child of a menubar. 
  
   | |||||||||||
Messaged when the menubar selection changes to activate or
 deactivate this menu. 
  
   | |||||||||||
Removes the specified menu item from this menu. 
  
   | |||||||||||
Removes the component  
  
  c from this menu. | |||||||||||
Removes the menu item at the specified index from this menu. 
  
   | |||||||||||
Removes all menu items from this menu. 
  
   | |||||||||||
Removes a listener for menu events. 
  
   | |||||||||||
setAccelerator is not defined for JMenu. | |||||||||||
Sets the language-sensitive orientation that is to be used to order
 the elements or text within this component. 
  
   | |||||||||||
Sets the suggested delay before the menu's  
  
  PopupMenu
 is popped up or down. | |||||||||||
Sets the location of the popup component. 
  
   | |||||||||||
Sets the data model for the "menu button" -- the label
 that the user clicks to open or close the menu. 
  
   | |||||||||||
Sets the visibility of the menu's popup. 
  
   | |||||||||||
Sets the selection status of the menu. 
  
   | |||||||||||
Resets the UI property with a value from the current look and feel. 
  
   | |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Returns a properly configured  
  
  PropertyChangeListener
 which updates the control as changes to the Action occur. | |||||||||||
Factory method which creates the  
  
  JMenuItem for
 Actions added to the JMenu. | |||||||||||
Creates a window-closing listener for the popup. 
  
   | |||||||||||
Notifies all listeners that have registered interest for
 notification on this event type. 
  
   | |||||||||||
Notifies all listeners that have registered interest for
 notification on this event type. 
  
   | |||||||||||
Notifies all listeners that have registered interest for
 notification on this event type. 
  
   | |||||||||||
Computes the origin for the  
  
  JMenu's popup menu. | |||||||||||
Returns a string representation of this  
  
  JMenu. | |||||||||||
Processes key stroke events such as mnemonics and accelerators. 
  
   | |||||||||||
| 
  [Expand]
   Inherited Methods  | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
   
From class
  javax.swing.JMenuItem
 | |||||||||||
   
From class
  javax.swing.AbstractButton
 | |||||||||||
   
From class
  javax.swing.JComponent
 | |||||||||||
   
From class
  java.awt.Container
 | |||||||||||
   
From class
  java.awt.Component
 | |||||||||||
   
From class
  java.lang.Object
 | |||||||||||
   
From interface
  java.awt.ItemSelectable
 | |||||||||||
   
From interface
  java.awt.MenuContainer
 | |||||||||||
   
From interface
  java.awt.image.ImageObserver
 | |||||||||||
   
From interface
  javax.accessibility.Accessible
 | |||||||||||
   
From interface
  javax.swing.MenuElement
 | |||||||||||
Constructs a new JMenu with no text.
Constructs a new JMenu with the supplied string
 as its text.
| s | the text for the menu label | 
|---|
Constructs a menu whose properties are taken from the
 Action supplied.
| a | an Action | 
        
|---|
Constructs a new JMenu with the supplied string as
 its text and specified as a tear-off menu or not.
| s | the text for the menu label | 
|---|---|
| b | can the menu be torn off (not yet implemented) | 
Adds the specified component to this container at the given
 position. If index equals -1, the component will
 be appended to the end.
| c | the Component to add | 
        
|---|---|
| index | the position at which to insert the component | 
Component addedAppends a menu item to the end of this menu. Returns the menu item added.
| menuItem | the JMenuitem to be added | 
        
|---|
JMenuItem added
Appends a component to the end of this menu. Returns the component added.
| c | the Component to add | 
        
|---|
Component added
Creates a new menu item attached to the specified
 Action object and appends it to the end of this menu.
| a | the Action for the menu item to be added | 
        
|---|
Creates a new menu item with the specified text and appends it to the end of this menu.
| s | the string for the menu item to be added | 
|---|
Adds a listener for menu events.
| l | the listener to be added | 
|---|
Appends a new separator to the end of the menu.
Sets the ComponentOrientation property of this menu
 and all components contained within it. This includes all
 components returned by getMenuComponents.
| o | the new component orientation of this menu and the components contained within it. | 
|---|
| NullPointerException | if orientation is null. | 
        
|---|
Programmatically performs a "click".  This overrides the method
 AbstractButton.doClick in order to make the menu pop up.
| pressTime | indicates the number of milliseconds the button was pressed for | 
|---|
Gets the AccessibleContext associated with this JMenu. For JMenus, the AccessibleContext takes the form of an AccessibleJMenu. A new AccessibleJMenu instance is created if necessary.
Returns the java.awt.Component used to
 paint this MenuElement.
 The returned component is used to convert events and detect if
 an event is inside a menu component.
Component that paints this menu item
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 the delay property.
 In most cases, the delay is not observed for top level menus
 or while dragging.  The default for delay is 0.
 This method is a property of the look and feel code and is used
 to manage the idiosyncracies of the various UI implementations.
delay property
Returns the JMenuItem at the specified position.
 If the component at pos is not a menu item,
 null is returned.
 This method is included for AWT compatibility.
| pos | an integer specifying the position | 
|---|
null
          if the item as the specified position is not a menu item
| IllegalArgumentException | if the value of
                       pos < 0 | 
        
|---|
Returns the number of items on the menu, including separators. This method is included for AWT compatibility.
Returns the component at position n.
| n | the position of the component to be returned | 
|---|
null
                  if there is no popup menu
Returns the number of components on the menu.
Returns an array of Components of the menu's
 subcomponents.  Note that this returns all Components
 in the popup menu, including separators.
Components or an empty array
          if there is no popup menu
Returns an array of all the MenuListeners added
 to this JMenu with addMenuListener().
MenuListeners added or an empty
         array if no listeners have been addedReturns the popupmenu associated with this menu. If there is no popupmenu, it will create one.
Returns an array of MenuElements containing the submenu
 for this menu component.  If popup menu is null returns
 an empty array.  This method is required to conform to the
 MenuElement interface.  Note that since
 JSeparators do not conform to the MenuElement
 interface, this array will only contain JMenuItems.
MenuElement objects
Returns the name of the L&F class that renders this component.
Inserts a new menu item attached to the specified Action
 object at a given position.
| a | the Action object for the menu item to add | 
        
|---|---|
| pos | an integer specifying the position at which to add the new menu item | 
| IllegalArgumentException | if the value of
                  pos < 0
 | 
        
|---|
Inserts a new menu item with the specified text at a given position.
| s | the text for the menu item to add | 
|---|---|
| pos | an integer specifying the position at which to add the new menu item | 
| IllegalArgumentException | when the value of
                  pos < 0
 | 
        
|---|
Inserts the specified JMenuitem at a given position.
| mi | the JMenuitem to add | 
        
|---|---|
| pos | an integer specifying the position at which to add the
               new JMenuitem | 
        
| IllegalArgumentException | if the value of
                  pos < 0
 | 
        
|---|
Inserts a separator at the specified position.
| index | an integer specifying the position at which to insert the menu separator | 
|---|
| IllegalArgumentException | if the value of
                       index < 0
 | 
        
|---|
Returns true if the specified component exists in the submenu hierarchy.
| c | the Component to be tested | 
        
|---|
Component exists, false otherwise
Returns true if the menu's popup window is visible.
Returns true if the menu is currently selected (highlighted).
Returns true if the menu can be torn off. This method is not yet implemented.
| Error | if invoked -- this method is not yet implemented | 
|---|
Returns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.
Messaged when the menubar selection changes to activate or
 deactivate this menu.
 Overrides JMenuItem.menuSelectionChanged.
| isIncluded | true if this menu is active, false if it is not | 
|---|
Removes the specified menu item from this menu. If there is no popup menu, this method will have no effect.
| item | the JMenuItem to be removed from the menu
 | 
        
|---|
Removes the component c from this menu.
| c | the component to be removed | 
|---|
Removes the menu item at the specified index from this menu.
| pos | the position of the item to be removed | 
|---|
| IllegalArgumentException | if the value of
                       pos < 0, or if pos
                       is greater than the number of menu items
 | 
        
|---|
Removes all menu items from this menu.
Removes a listener for menu events.
| l | the listener to be removed | 
|---|
setAccelerator is not defined for JMenu.
 Use setMnemonic instead.
| keyStroke | the keystroke combination which will invoke
                  the JMenuItem's actionlisteners
                  without navigating the menu hierarchy | 
        
|---|
| Error | if invoked -- this method is not defined for JMenu.
                  Use setMnemonic instead | 
        
|---|
Sets the language-sensitive orientation that is to be used to order
 the elements or text within this component.  Language-sensitive
 LayoutManager and Component
 subclasses will use this property to
 determine how to lay out and draw components.
 
 At construction time, a component's orientation is set to
 ComponentOrientation.UNKNOWN,
 indicating that it has not been specified
 explicitly.  The UNKNOWN orientation behaves the same as
 ComponentOrientation.LEFT_TO_RIGHT.
 
 To set the orientation of a single component, use this method.
 To set the orientation of an entire component
 hierarchy, use
 applyComponentOrientation.
Sets the suggested delay before the menu's PopupMenu
 is 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 idiosyncracies of the various UI implementations.
| d | the number of milliseconds to delay | 
|---|
| IllegalArgumentException | if d
                       is less than 0 | 
        
|---|
Sets the location of the popup component.
| x | the x coordinate of the popup's new position | 
|---|---|
| y | the y coordinate of the popup's new position | 
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.
| newModel | the ButtonModel | 
        
|---|
Sets the visibility of the menu's popup. If the menu is not enabled, this method will have no effect.
| b | a boolean value -- true to make the menu visible, false to hide it | 
|---|
Sets the selection status of the menu.
| b | true to select (highlight) the menu; false to de-select the menu | 
|---|
Resets the UI property with a value from the current look and feel.
Returns a properly configured PropertyChangeListener
 which updates the control as changes to the Action occur.
Factory method which creates the JMenuItem for
 Actions added to the JMenu.
| a | the Action for the menu item to be added | 
        
|---|
Creates a window-closing listener for the popup.
| p | the JPopupMenu | 
        
|---|
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.
| Error | if there is a null listener | 
        
|---|
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.
| Error | if there is a null listener | 
        
|---|
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.
| Error | if there is a null listener | 
        
|---|
Computes the origin for the JMenu's popup menu.
 This method uses Look and Feel properties named
 Menu.menuPopupOffsetX,
 Menu.menuPopupOffsetY,
 Menu.submenuPopupOffsetX, and
 Menu.submenuPopupOffsetY
 to adjust the exact location of popup.
Point in the coordinate space of the
          menu which should be used as the origin
          of the JMenu's popup menuReturns a string representation of this JMenu. 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
 be null.
Processes key stroke events such as mnemonics and accelerators.
| evt | the key event to be processed | 
|---|