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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
(->j-menu)
(->j-menu s)
(->j-menu s b)
Constructor.
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 - java.lang.String
b - can the menu be torn off (not yet implemented) - boolean
Constructor. 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 - `java.lang.String` b - can the menu be torn off (not yet implemented) - `boolean`
(add this menu-item)
(add this c index)
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 - java.awt.Component
index - the position at which to insert the component - int
returns: the Component added - java.awt.Component
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 - `java.awt.Component` index - the position at which to insert the component - `int` returns: the Component added - `java.awt.Component`
(add-menu-listener this l)
Adds a listener for menu events.
l - the listener to be added - javax.swing.event.MenuListener
Adds a listener for menu events. l - the listener to be added - `javax.swing.event.MenuListener`
(add-separator this)
Appends a new separator to the end of the menu.
Appends a new separator to the end of the menu.
(apply-component-orientation this o)
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. - java.awt.ComponentOrientation
throws: java.lang.NullPointerException - if orientation is null.
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. - `java.awt.ComponentOrientation` throws: java.lang.NullPointerException - if orientation is null.
(do-click this press-time)
Programmatically performs a "click". This overrides the method AbstractButton.doClick in order to make the menu pop up.
press-time - indicates the number of milliseconds the button was pressed for - int
Programmatically performs a "click". This overrides the method AbstractButton.doClick in order to make the menu pop up. press-time - indicates the number of milliseconds the button was pressed for - `int`
(get-accessible-context this)
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: an AccessibleJMenu that serves as the
AccessibleContext of this JMenu - javax.accessibility.AccessibleContext
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: an AccessibleJMenu that serves as the AccessibleContext of this JMenu - `javax.accessibility.AccessibleContext`
(get-component this)
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.
returns: the Component that paints this menu item - java.awt.Component
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. returns: the Component that paints this menu item - `java.awt.Component`
(get-delay this)
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 idiosyncrasies of the various UI implementations.
returns: the delay property - int
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 idiosyncrasies of the various UI implementations. returns: the delay property - `int`
(get-item this pos)
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 - int
returns: the menu item at the specified position; or null
if the item as the specified position is not a menu item - javax.swing.JMenuItem
throws: java.lang.IllegalArgumentException - if the value of pos < 0
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 - `int` returns: the menu item at the specified position; or null if the item as the specified position is not a menu item - `javax.swing.JMenuItem` throws: java.lang.IllegalArgumentException - if the value of pos < 0
(get-item-count this)
Returns 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 - int
Returns 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 - `int`
(get-menu-component this n)
Returns the component at position n.
n - the position of the component to be returned - int
returns: the component requested, or null
if there is no popup menu - java.awt.Component
Returns the component at position n. n - the position of the component to be returned - `int` returns: the component requested, or null if there is no popup menu - `java.awt.Component`
(get-menu-component-count this)
Returns the number of components on the menu.
returns: an integer containing the number of components on the menu - int
Returns the number of components on the menu. returns: an integer containing the number of components on the menu - `int`
(get-menu-components this)
Returns an array of Components of the menu's subcomponents. Note that this returns all Components in the popup menu, including separators.
returns: an array of Components or an empty array
if there is no popup menu - java.awt.Component[]
Returns an array of Components of the menu's subcomponents. Note that this returns all Components in the popup menu, including separators. returns: an array of Components or an empty array if there is no popup menu - `java.awt.Component[]`
(get-menu-listeners this)
Returns an array of all the MenuListeners added to this JMenu with addMenuListener().
returns: all of the MenuListeners added or an empty
array if no listeners have been added - javax.swing.event.MenuListener[]
Returns an array of all the MenuListeners added to this JMenu with addMenuListener(). returns: all of the MenuListeners added or an empty array if no listeners have been added - `javax.swing.event.MenuListener[]`
(get-popup-menu this)
Returns the popupmenu associated with this menu. If there is no popupmenu, it will create one.
returns: javax.swing.JPopupMenu
Returns the popupmenu associated with this menu. If there is no popupmenu, it will create one. returns: `javax.swing.JPopupMenu`
(get-sub-elements this)
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.
returns: an array of MenuElement objects - javax.swing.MenuElement[]
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. returns: an array of MenuElement objects - `javax.swing.MenuElement[]`
(get-ui-class-id this)
Returns the name of the L&F class that renders this component.
returns: the string "MenuUI" - java.lang.String
Returns the name of the L&F class that renders this component. returns: the string "MenuUI" - `java.lang.String`
(insert this s pos)
Inserts a new menu item with the specified text at a given position.
s - the text for the menu item to add - java.lang.String
pos - an integer specifying the position at which to add the new menu item - int
throws: java.lang.IllegalArgumentException - when 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 - `java.lang.String` pos - an integer specifying the position at which to add the new menu item - `int` throws: java.lang.IllegalArgumentException - when the value of pos < 0
(insert-separator this index)
Inserts a separator at the specified position.
index - an integer specifying the position at which to insert the menu separator - int
throws: java.lang.IllegalArgumentException - if the value of index < 0
Inserts a separator at the specified position. index - an integer specifying the position at which to insert the menu separator - `int` throws: java.lang.IllegalArgumentException - if the value of index < 0
(menu-component? this c)
Returns true if the specified component exists in the submenu hierarchy.
c - the Component to be tested - java.awt.Component
returns: true if the Component exists, false otherwise - boolean
Returns true if the specified component exists in the submenu hierarchy. c - the Component to be tested - `java.awt.Component` returns: true if the Component exists, false otherwise - `boolean`
(menu-selection-changed this is-included)
Messaged when the menubar selection changes to activate or deactivate this menu. Overrides JMenuItem.menuSelectionChanged.
is-included - true if this menu is active, false if it is not - boolean
Messaged when the menubar selection changes to activate or deactivate this menu. Overrides JMenuItem.menuSelectionChanged. is-included - true if this menu is active, false if it is not - `boolean`
(popup-menu-visible? this)
Returns true if the menu's popup window is visible.
returns: true if the menu is visible, else false - boolean
Returns true if the menu's popup window is visible. returns: true if the menu is visible, else false - `boolean`
(remove this item)
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 - javax.swing.JMenuItem
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 - `javax.swing.JMenuItem`
(remove-all this)
Removes all menu items from this menu.
Removes all menu items from this menu.
(remove-menu-listener this l)
Removes a listener for menu events.
l - the listener to be removed - javax.swing.event.MenuListener
Removes a listener for menu events. l - the listener to be removed - `javax.swing.event.MenuListener`
(selected? this)
Returns true if the menu is currently selected (highlighted).
returns: true if the menu is selected, else false - boolean
Returns true if the menu is currently selected (highlighted). returns: true if the menu is selected, else false - `boolean`
(set-accelerator this key-stroke)
setAccelerator is not defined for JMenu. Use setMnemonic instead.
key-stroke - the keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy - javax.swing.KeyStroke
throws: java.lang.Error - if invoked -- this method is not defined for JMenu. Use setMnemonic instead
setAccelerator is not defined for JMenu. Use setMnemonic instead. key-stroke - the keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy - `javax.swing.KeyStroke` throws: java.lang.Error - if invoked -- this method is not defined for JMenu. Use setMnemonic instead
(set-component-orientation this o)
Description copied from class: Component
o - java.awt.ComponentOrientation
Description copied from class: Component o - `java.awt.ComponentOrientation`
(set-delay this d)
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 idiosyncrasies of the various UI implementations.
d - the number of milliseconds to delay - int
throws: java.lang.IllegalArgumentException - if d is less than 0
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 idiosyncrasies of the various UI implementations. d - the number of milliseconds to delay - `int` throws: java.lang.IllegalArgumentException - if d is less than 0
(set-menu-location this x y)
Sets the location of the popup component.
x - the x coordinate of the popup's new position - int
y - the y coordinate of the popup's new position - int
Sets the location of the popup component. x - the x coordinate of the popup's new position - `int` y - the y coordinate of the popup's new position - `int`
(set-model this new-model)
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.
new-model - the ButtonModel - javax.swing.ButtonModel
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu. new-model - the ButtonModel - `javax.swing.ButtonModel`
(set-popup-menu-visible this b)
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 - boolean
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 - `boolean`
(set-selected this b)
Sets the selection status of the menu.
b - true to select (highlight) the menu; false to de-select the menu - boolean
Sets the selection status of the menu. b - true to select (highlight) the menu; false to de-select the menu - `boolean`
(tear-off? this)
Returns 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 - boolean
throws: java.lang.Error - if invoked -- this method is not yet implemented
Returns 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 - `boolean` throws: java.lang.Error - if invoked -- this method is not yet implemented
(top-level-menu? this)
Returns 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 - boolean
Returns 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 - `boolean`
(update-ui this)
Resets the UI property with a value from the current look and feel.
Resets the UI property with a value from the current look and feel.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close