Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: MenuBar [javadoc | source]
java.lang.Object
   java.awt.MenuComponent
      java.awt.MenuBar

All Implemented Interfaces:
    MenuContainer, Accessible, Serializable

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, MenuBar#shortcuts and MenuBar#getShortcutMenuItem that retrieve information about the shortcuts a given menu bar is managing.

Nested Class Summary:
protected class  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. 

Field Summary
 Vector menus    This field represents a vector of the actual menus that will be part of the MenuBar. 
 Menu helpMenu    This menu is a special menu dedicated to help. The one thing to note about this menu is that on some platforms it appears at the right edge of the menubar. 
Fields inherited from java.awt.MenuComponent:
peer,  parent,  appContext,  font,  newEventsOnly,  actionListenerK,  itemListenerK,  accessibleContext
Constructor:
 public MenuBar() throws HeadlessException 
    Creates a new menu bar.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Method from java.awt.MenuBar Summary:
add,   addNotify,   constructComponentName,   countMenus,   deleteShortcut,   getAccessibleChildIndex,   getAccessibleContext,   getHelpMenu,   getMenu,   getMenuCount,   getMenuCountImpl,   getMenuImpl,   getShortcutMenuItem,   handleShortcut,   remove,   remove,   removeNotify,   setHelpMenu,   shortcuts
Methods from java.awt.MenuComponent:
constructComponentName,   dispatchEvent,   dispatchEventImpl,   eventEnabled,   getAccessControlContext,   getAccessibleChildIndex,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getFont,   getFont_NoClientCode,   getName,   getParent,   getParent_NoClientCode,   getPeer,   getTreeLock,   paramString,   postEvent,   processEvent,   removeNotify,   setFont,   setName,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.MenuBar Detail:
 public 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.
 public  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.
 String constructComponentName() 
    Construct a name for this MenuComponent. Called by getName() when the name is null.
 public int countMenus() 
Deprecated! As - of JDK version 1.1, replaced by getMenuCount().

 public  void deleteShortcut(MenuShortcut s) 
    Deletes the specified menu shortcut.
 int getAccessibleChildIndex(MenuComponent child) 
    Defined in MenuComponent. Overridden here.
 public 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.
 public Menu getHelpMenu() 
    Gets the help menu on the menu bar.
 public Menu getMenu(int i) 
    Gets the specified menu.
 public int getMenuCount() 
    Gets the number of menus on the menu bar.
 final int getMenuCountImpl() 
 final Menu getMenuImpl(int i) 
 public MenuItem 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.
 boolean handleShortcut(KeyEvent e) 
 public  void remove(int index) 
    Removes the menu located at the specified index from this menu bar.
 public  void remove(MenuComponent m) 
    Removes the specified menu component from this menu bar.
 public  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.
 public  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.
 public synchronized Enumeration<MenuShortcut> shortcuts() 
    Gets an enumeration of all menu shortcuts this menu bar is managing.