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(java.awt.MenuShortcut) that retrieve information about the shortcuts a given menu bar is managing.
| Modifier and Type | Class | Description | 
|---|---|---|
| protected class  | MenuBar.AccessibleAWTMenuBar | Inner class of MenuBar used to provide default support for accessibility. | 
MenuComponent.AccessibleAWTMenuComponent
| Constructor | Description | 
|---|---|
| MenuBar() | Creates a new menu bar. | 
| 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  MenuItemassociated with the specifiedMenuShortcutobject, ornullif 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. | 
dispatchEvent, getFont, getName, getParent, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getFont, postEvent
public MenuBar() throws HeadlessException
HeadlessException - if GraphicsEnvironment.isHeadless() returns true.public void addNotify()
public void removeNotify()
removeNotify in class MenuComponent
public Menu getHelpMenu()
public void setHelpMenu(Menu m)
m - the menu to be set as the help menupublic Menu add(Menu m)
m - the menu to be addedpublic void remove(int index)
index - the position of the menu to be removed.public void remove(MenuComponent m)
remove in interface MenuContainer
m - the menu component to be removed.public int getMenuCount()
@Deprecated public int countMenus()
getMenuCount().public Menu getMenu(int i)
i - the index position of the menu to be returned.public Enumeration<MenuShortcut> shortcuts()
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.s - the specified menu shortcut.public void deleteShortcut(MenuShortcut s)
s - the menu shortcut to delete.public AccessibleContext getAccessibleContext()
getAccessibleContext in interface Accessible
getAccessibleContext in class MenuComponent
    © 1993, 2023, 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.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/MenuBar.html
  
getMenuCount().