Class MenuBar
- All Implemented Interfaces:
MenuContainer, Serializable, Accessible
public class MenuBar extends MenuComponent implements MenuContainer, Accessible
MenuBar class encapsulates the platform's concept of a menu bar bound to a frame. In order to associate the menu bar with a Frame object, call the frame's setMenuBar method. This is what a menu bar might look like:
A menu bar handles keyboard shortcuts for menu items, passing them along to its child menus. (Keyboard shortcuts, which are optional, provide the user with an alternative to the mouse for invoking a menu item and the action that is associated with it.) Each menu item can maintain an instance of MenuShortcut. The MenuBar class defines several methods, shortcuts() and getShortcutMenuItem(MenuShortcut) that retrieve information about the shortcuts a given menu bar is managing.
- Since:
- 1.0
- See Also:
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
protected class |
MenuBar.AccessibleAWTMenuBar |
Inner class of MenuBar used to provide default support for accessibility. |
Nested classes/interfaces declared in class MenuComponent
MenuComponent.AccessibleAWTMenuComponent | Modifier and Type | Class | Description |
|---|---|---|
protected class |
MenuComponent.AccessibleAWTMenuComponent |
Inner class of MenuComponent used to provide default support for accessibility. |
Constructor Summary
| Constructor | Description |
|---|---|
MenuBar() |
Creates a new menu bar. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Menu |
add |
Adds the specified menu to the menu bar. |
void |
addNotify() |
Creates the menu bar's peer. |
int |
countMenus() |
Deprecated. |
void |
deleteShortcut |
Deletes the specified menu shortcut. |
AccessibleContext |
getAccessibleContext() |
Gets the AccessibleContext associated with this MenuBar. |
Menu |
getHelpMenu() |
Gets the help menu on the menu bar. |
Menu |
getMenu |
Gets the specified menu. |
int |
getMenuCount() |
Gets the number of menus on the menu bar. |
MenuItem |
getShortcutMenuItem |
Gets the instance of MenuItem associated with the specified MenuShortcut object, or null if none of the menu items being managed by this menu bar is associated with the specified menu shortcut. |
void |
remove |
Removes the menu located at the specified index from this menu bar. |
void |
remove |
Removes the specified menu component from this menu bar. |
void |
removeNotify() |
Removes the menu bar's peer. |
void |
setHelpMenu |
Sets the specified menu to be this menu bar's help menu. |
Enumeration |
shortcuts() |
Gets an enumeration of all menu shortcuts this menu bar is managing. |
Methods declared in class MenuComponent
dispatchEvent, getFont, getName, getParent, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toString | Modifier and Type | Method | Description |
|---|---|---|
final void |
dispatchEvent |
Delivers an event to this component or one of its sub components. |
Font |
getFont() |
Gets the font used for this menu component. |
String |
getName() |
Gets the name of the menu component. |
MenuContainer |
getParent() |
Returns the parent container for this menu component. |
protected final Object |
getTreeLock() |
Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations. |
protected String |
paramString() |
Returns a string representing the state of this MenuComponent. |
boolean |
postEvent |
Deprecated. As of JDK version 1.1, replaced by dispatchEvent. |
protected void |
processEvent |
Processes events occurring on this menu component. |
void |
setFont |
Sets the font to be used for this menu component to the specified font. |
void |
setName |
Sets the name of the component to the specified string. |
String |
toString() |
Returns a representation of this menu component as a string. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
MenuBar
public MenuBar() throws HeadlessException
- Throws:
-
HeadlessException- if GraphicsEnvironment.isHeadless() returns true. - See Also:
Method Details
addNotify
public void addNotify()
removeNotify
public void removeNotify()
- Overrides:
-
removeNotifyin classMenuComponent
getHelpMenu
public Menu getHelpMenu()
- Returns:
- the help menu on this menu bar.
setHelpMenu
public void setHelpMenu(Menu m)
- Parameters:
-
m- the menu to be set as the help menu
add
public Menu add(Menu m)
- Parameters:
-
m- the menu to be added - Returns:
- the menu added
- See Also:
remove
public void remove(int index)
- Parameters:
-
index- the position of the menu to be removed. - See Also:
remove
public void remove(MenuComponent m)
- Specified by:
-
removein interfaceMenuContainer - Parameters:
-
m- the menu component to be removed. - See Also:
getMenuCount
public int getMenuCount()
- Returns:
- the number of menus on the menu bar.
- Since:
- 1.1
countMenus
@Deprecated public int countMenus()
getMenuCount().- Returns:
- the number of menus on the menu bar.
getMenu
public Menu getMenu(int i)
- Parameters:
-
i- the index position of the menu to be returned. - Returns:
- the menu at the specified index of this menu bar.
shortcuts
public Enumeration<MenuShortcut> shortcuts()
- Returns:
- an enumeration of menu shortcuts that this menu bar is managing.
- Since:
- 1.1
- See Also:
getShortcutMenuItem
public MenuItem getShortcutMenuItem(MenuShortcut s)
MenuItem associated with the specified MenuShortcut object, or null if none of the menu items being managed by this menu bar is associated with the specified menu shortcut.- Parameters:
-
s- the specified menu shortcut. - Returns:
- the menu item for the specified shortcut.
- Since:
- 1.1
- See Also:
deleteShortcut
public void deleteShortcut(MenuShortcut s)
- Parameters:
-
s- the menu shortcut to delete. - Since:
- 1.1
getAccessibleContext
public AccessibleContext getAccessibleContext()
- Specified by:
-
getAccessibleContextin interfaceAccessible - Overrides:
-
getAccessibleContextin classMenuComponent - Returns:
- an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar
- Since:
- 1.3
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
getMenuCount().