java.awt
Class MenuBar

java.lang.Object
  |
  +--java.awt.MenuComponent
        |
        +--java.awt.MenuBar
All Implemented Interfaces:
Accessible, MenuContainer, Serializable

public class MenuBar
extends MenuComponent
implements MenuContainer, Accessible

The 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.

Since:
JDK1.0
See Also:
Frame, Frame.setMenuBar(java.awt.MenuBar), Menu, MenuItem, MenuShortcut, Serialized Form

Inner Class Summary
protected  class MenuBar.AccessibleAWTMenuBar
MenuBar.AccessibleAWTMenuBar
Inner class of MenuBar used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

This class implements accessibility support for the MenuBar class. It provides an implementation of the Java Accessibility API appropriate to menu bar user-interface elements.

 
Inner classes inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
MenuBar
copy->  new MenuBar()
copy->  <MenuBar var> = new MenuBar();
Creates a new menu bar.
 
Method Summary
 Menu add(Menu m)
copy->  .add( )
copy->  <Menu var>=<MenuBar>.add(<Menu m>);
Adds the specified menu to the menu bar.
Parameters:
m - the menu to be added.
Returns:
the menu added.
See Also:
remove(int), remove(java.awt.MenuComponent)
 void addNotify()
copy->  .addNotify()
copy->  <MenuBar>.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.
 int countMenus()
copy->  .countMenus()
copy->  <int var>=<MenuBar>.countMenus();
Deprecated. As of JDK version 1.1, replaced by getMenuCount().

 void deleteShortcut(MenuShortcut s)
copy->  .deleteShortcut( )
copy->  <MenuBar>.deleteShortcut(<MenuShortcut s>);
Deletes the specified menu shortcut.
Parameters:
s - the menu shortcut to delete.
Since:
JDK1.1
 AccessibleContext getAccessibleContext()
copy->  .getAccessibleContext()
copy->  <AccessibleContext var>=<MenuBar>.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:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class MenuComponent
Returns:
an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar
 Menu getHelpMenu()
copy->  .getHelpMenu()
copy->  <Menu var>=<MenuBar>.getHelpMenu();
Gets the help menu on the menu bar.
Returns:
the help menu on this menu bar.
 Menu getMenu(int i)
copy->  .getMenu( )
copy->  <Menu var>=<MenuBar>.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.
 int getMenuCount()
copy->  .getMenuCount()
copy->  <int var>=<MenuBar>.getMenuCount();
Gets the number of menus on the menu bar.
Returns:
the number of menus on the menu bar.
Since:
JDK1.1
 MenuItem getShortcutMenuItem(MenuShortcut s)
copy->  .getShortcutMenuItem( )
copy->  <MenuItem var>=<MenuBar>.getShortcutMenuItem(<MenuShortcut s>);
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.
Parameters:
s - the specified menu shortcut.
Since:
JDK1.1
See Also:
MenuItem, MenuShortcut
 void remove(int index)
copy->  .remove( )
copy->  <MenuBar>.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)
 void remove(MenuComponent m)
copy->  .remove( )
copy->  <MenuBar>.remove(<MenuComponent m>);
Removes the specified menu component from this menu bar.
Specified by:
remove in interface MenuContainer
Parameters:
m - the menu component to be removed.
See Also:
add(java.awt.Menu)
 void removeNotify()
copy->  .removeNotify()
copy->  <MenuBar>.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:
removeNotify in class MenuComponent
 void setHelpMenu(Menu m)
copy->  .setHelpMenu( )
copy->  <MenuBar>.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
 Enumeration shortcuts()
copy->  .shortcuts()
copy->  <Enumeration var>=<MenuBar>.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:
JDK1.1
See Also:
MenuShortcut
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent