- java.lang.Object
- 
- java.awt.MenuComponent
- 
- java.awt.MenuBar
 
 
- 
- All Implemented Interfaces:
- MenuContainer,- Serializable,- Accessible
 
 public class MenuBar extends MenuComponent implements MenuContainer, Accessible TheMenuBarclass encapsulates the platform's concept of a menu bar bound to a frame. In order to associate the menu bar with aFrameobject, call the frame'ssetMenuBarmethod.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. TheMenuBarclass defines several methods,shortcuts()andgetShortcutMenuItem(java.awt.MenuShortcut)that retrieve information about the shortcuts a given menu bar is managing.- Since:
- 1.0
- See Also:
- Frame,- Frame.setMenuBar(java.awt.MenuBar),- Menu,- MenuItem,- MenuShortcut, Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classMenuBar.AccessibleAWTMenuBarInner class of MenuBar used to provide default support for accessibility.- 
Nested classes/interfaces declared in class java.awt.MenuComponentMenuComponent.AccessibleAWTMenuComponent
 
- 
 - 
Constructor SummaryConstructors Constructor Description MenuBar()Creates a new menu bar.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Menuadd(Menu m)Adds the specified menu to the menu bar.voidaddNotify()Creates the menu bar's peer.intcountMenus()Deprecated.As of JDK version 1.1, replaced bygetMenuCount().voiddeleteShortcut(MenuShortcut s)Deletes the specified menu shortcut.AccessibleContextgetAccessibleContext()Gets the AccessibleContext associated with this MenuBar.MenugetHelpMenu()Gets the help menu on the menu bar.MenugetMenu(int i)Gets the specified menu.intgetMenuCount()Gets the number of menus on the menu bar.MenuItemgetShortcutMenuItem(MenuShortcut s)Gets the instance ofMenuItemassociated with the specifiedMenuShortcutobject, ornullif none of the menu items being managed by this menu bar is associated with the specified menu shortcut.voidremove(int index)Removes the menu located at the specified index from this menu bar.voidremove(MenuComponent m)Removes the specified menu component from this menu bar.voidremoveNotify()Removes the menu bar's peer.voidsetHelpMenu(Menu m)Sets the specified menu to be this menu bar's help menu.Enumeration<MenuShortcut>shortcuts()Gets an enumeration of all menu shortcuts this menu bar is managing.- 
Methods declared in class java.awt.MenuComponentdispatchEvent, getFont, getName, getParent, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toString
 - 
Methods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods declared in interface java.awt.MenuContainergetFont, postEvent
 
- 
 
- 
- 
- 
Constructor Detail- 
MenuBarpublic MenuBar() throws HeadlessExceptionCreates a new menu bar.- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true.
- See Also:
- GraphicsEnvironment.isHeadless()
 
 
- 
 - 
Method Detail- 
addNotifypublic void addNotify() Creates the menu bar's peer. The peer allows us to change the appearance of the menu bar without changing any of the menu bar's functionality.
 - 
removeNotifypublic void removeNotify() Removes the menu bar's peer. The peer allows us to change the appearance of the menu bar without changing any of the menu bar's functionality.- Overrides:
- removeNotifyin class- MenuComponent
 
 - 
getHelpMenupublic Menu getHelpMenu() Gets the help menu on the menu bar.- Returns:
- the help menu on this menu bar.
 
 - 
setHelpMenupublic void setHelpMenu(Menu m) Sets the specified menu to be this menu bar's help menu. If this menu bar has an existing help menu, the old help menu is removed from the menu bar, and replaced with the specified menu.- Parameters:
- m- the menu to be set as the help menu
 
 - 
addpublic Menu add(Menu m) Adds the specified menu to the menu bar. If the menu has been part of another menu bar, removes it from that menu bar.- Parameters:
- m- the menu to be added
- Returns:
- the menu added
- See Also:
- remove(int),- remove(java.awt.MenuComponent)
 
 - 
removepublic void remove(int index) Removes the menu located at the specified index from this menu bar.- Parameters:
- index- the position of the menu to be removed.
- See Also:
- add(java.awt.Menu)
 
 - 
removepublic void remove(MenuComponent m) Removes the specified menu component from this menu bar.- Specified by:
- removein interface- MenuContainer
- Parameters:
- m- the menu component to be removed.
- See Also:
- add(java.awt.Menu)
 
 - 
getMenuCountpublic int getMenuCount() Gets the number of menus on the menu bar.- Returns:
- the number of menus on the menu bar.
- Since:
- 1.1
 
 - 
countMenus@Deprecated public int countMenus() Deprecated.As of JDK version 1.1, replaced bygetMenuCount().Gets the number of menus on the menu bar.- Returns:
- the number of menus on the menu bar.
 
 - 
getMenupublic Menu getMenu(int i) Gets the specified menu.- Parameters:
- i- the index position of the menu to be returned.
- Returns:
- the menu at the specified index of this menu bar.
 
 - 
shortcutspublic Enumeration<MenuShortcut> shortcuts() Gets an enumeration of all menu shortcuts this menu bar is managing.- Returns:
- an enumeration of menu shortcuts that this menu bar is managing.
- Since:
- 1.1
- See Also:
- MenuShortcut
 
 - 
getShortcutMenuItempublic MenuItem getShortcutMenuItem(MenuShortcut s) Gets the instance ofMenuItemassociated with the specifiedMenuShortcutobject, ornullif 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:
- MenuItem,- MenuShortcut
 
 - 
deleteShortcutpublic void deleteShortcut(MenuShortcut s) Deletes the specified menu shortcut.- Parameters:
- s- the menu shortcut to delete.
- Since:
- 1.1
 
 - 
getAccessibleContextpublic AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this MenuBar. For menu bars, the AccessibleContext takes the form of an AccessibleAWTMenuBar. A new AccessibleAWTMenuBar instance is created if necessary.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- MenuComponent
- Returns:
- an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar
- Since:
- 1.3
 
 
- 
 
-