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 java..
JMenuItem, JSeparator, JMenuBar, JPopupMenu
| Modifier and Type | Class and Description |
|---|---|
| protected class | JMenu.
This class implements accessibility support for the
|
| pack-priv class | |
| protected class | JMenu.
A listener class that watches for a popup window closing. |
| Modifier and Type | Field and Description |
|---|---|
| private Point | |
| private static final boolean | |
| private int | |
| private ChangeListener | |
| private MenuEvent | |
| protected JMenu. | popupListener
The window-closing listener for the popup. |
| private JPopupMenu | |
| private static final boolean | |
| private static final String | |
| private static final boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public JMenuItem | |
| public Component | Returns: theComponent addedthe c)Component to addOverrides java. Appends a component to the end of this menu. |
| public Component | Returns: theComponent addedthe c, int Component to addthe position at which to insert the component index)Overrides java. Adds the specified component to this container at the given position. |
| public JMenuItem | |
| public JMenuItem | |
| public void | |
| public void | |
| public void | applyComponentOrientation(ComponentOrientation
the new component orientation of this menu and
the components contained within it. o)Overrides java. Sets the |
| private MenuElement[] | |
| pack-priv void | |
| protected PropertyChangeListener | Returns: aPropertyChangeListener for ba menu item for which to create a b)PropertyChangeListenerReturns a properly configured |
| protected JMenuItem | Returns: the new menu itemthe a)Action for the menu item to be addedFactory method which creates the |
| private ChangeListener | |
| protected JMenu. | Returns: the new window-closing listenerthe p)JPopupMenuCreates a window-closing listener for the popup. |
| public void | doClick(int
indicates the number of milliseconds the
button was pressed for pressTime)Overrides javax. Programmatically performs a "click". |
| private void | |
| protected void | fireMenuCanceled()
Notifies all listeners that have registered interest for notification on this event type. |
| protected void | fireMenuDeselected()
Notifies all listeners that have registered interest for notification on this event type. |
| protected void | fireMenuSelected()
Notifies all listeners that have registered interest for notification on this event type. |
| public AccessibleContext | Returns: an AccessibleJMenu that serves as the AccessibleContext of this JMenuOverrides javax. Implements javax. Gets the AccessibleContext associated with this JMenu. |
| public Component | getComponent()
Overrides javax. Implements javax. Returns the |
| private Point | |
| public int | Returns: thedelay propertyReturns the suggested delay, in milliseconds, before submenus are popped up or down. |
| public JMenuItem | Returns: the menu item at the specified position; ornull
if the item as the specified position is not a menu iteman integer specifying the position pos)Returns the |
| public int | Returns: an integer equal to the number of items on the menuReturns the number of items on the menu, including separators. |
| public Component | Returns: the component requested, ornull
if there is no popup menuthe position of the component to be returned n)Returns the component at position |
| public int | Returns: an integer containing the number of components on the menuReturns the number of components on the menu. |
| public Component[] | Returns: an array ofComponents or an empty array
if there is no popup menuReturns an array of |
| public MenuListener[] | Returns: all of theMenuListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public JPopupMenu | Returns: theJPopupMenu associated with this menuReturns the popupmenu associated with this menu. |
| protected Point | Returns: aPoint in the coordinate space of the
menu which should be used as the origin
of the JMenu's popup menuComputes the origin for the |
| public MenuElement[] | Returns: an array ofMenuElement objectsOverrides javax. Implements javax. Returns an array of |
| public String | Returns: the string "MenuUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| pack-priv void | |
| public void | |
| public JMenuItem | |
| public JMenuItem | |
| public void | insertSeparator(int
an integer specifying the position at which to
insert the menu separator index)Inserts a separator at the specified position. |
| public boolean | Returns: true if theComponent exists, false otherwisethe c)Component to be testedReturns true if the specified component exists in the submenu hierarchy. |
| public boolean | Returns: true if the menu is visible, else falseReturns true if the menu's popup window is visible. |
| public boolean | Returns: true if the menu is selected, else falseOverrides javax. Returns true if the menu is currently selected (highlighted). |
| public boolean | Returns: true if the menu can be torn off, else falseReturns true if the menu can be torn off. |
| public boolean | Returns: true if the menu is activated from the menu bar; false if the menu is activated from a menu item on another menuReturns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar. |
| public void | menuSelectionChanged(boolean
true if this menu is active, false if
it is not isIncluded)Overrides javax. Implements javax. Messaged when the menubar selection changes to activate or deactivate this menu. |
| protected String | Returns: a string representation of this JMenu.Overrides javax. Returns a string representation of this |
| protected void | processKeyEvent(KeyEvent
the key event to be processed evt)Overrides javax. Processes key stroke events such as mnemonics and accelerators. |
| public void | |
| public void | remove(int
the position of the item to be removed pos)Overrides java. Removes the menu item at the specified index from this menu. |
| public void | remove(Component
the component to be removed c)Overrides java. Removes the component |
| public void | |
| public void | |
| public void | setAccelerator(KeyStroke
the keystroke combination which will invoke
the keyStroke)JMenuItem's actionlisteners
without navigating the menu hierarchyOverrides javax.
|
| public void | setComponentOrientation(ComponentOrientation
the new orientation for this menu and
its associated popup menu. o)Overrides java. Sets the orientation for this menu and its associated popup menu
determined by the |
| public void | setDelay(int
the number of milliseconds to delay d)Sets the suggested delay before the menu's |
| public void | setMenuLocation(int
the x coordinate of the popup's new position x, int the y coordinate of the popup's new position y)Sets the location of the popup component. |
| public void | setModel(ButtonModel
the newModel)ButtonModelOverrides javax. Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu. |
| public void | setPopupMenuVisible(boolean
a boolean value -- true to make the menu visible,
false to hide it b)Sets the visibility of the menu's popup. |
| public void | setSelected(boolean
true to select (highlight) the menu; false to de-select
the menu b)Overrides javax. Sets the selection status of the menu. |
| private Point | |
| private Point | |
| public void | updateUI()
Overrides javax. Resets the UI property with a value from the current look and feel. |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |