java.awt
Class MenuBar

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent 
      extended by java.awt.MenuBar
All Implemented Interfaces:
MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer , Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible

public class MenuBar
extends MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
implements MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer , Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.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:

ALIGN=center HSPACE=10 VSPACE=7>

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() sample code for java.awt.MenuBar.shortcuts() definition code for java.awt.MenuBar.shortcuts() and getShortcutMenuItem(java.awt.MenuShortcut) sample code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut) definition code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut) that retrieve information about the shortcuts a given menu bar is managing.

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

Nested Class Summary
protected  class MenuBar.AccessibleAWTMenuBar sample code for java.awt.MenuBar.AccessibleAWTMenuBar definition code for java.awt.MenuBar.AccessibleAWTMenuBar
          Inner class of MenuBar used to provide default support for accessibility.
 
Nested classes/interfaces inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent sample code for java.awt.MenuComponent.AccessibleAWTMenuComponent definition code for java.awt.MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
MenuBar sample code for java.awt.MenuBar.MenuBar() definition code for java.awt.MenuBar.MenuBar() ()
          Creates a new menu bar.
 
Method Summary
 Menu sample code for java.awt.Menu definition code for java.awt.Menu add sample code for java.awt.MenuBar.add(java.awt.Menu) definition code for java.awt.MenuBar.add(java.awt.Menu) (Menu sample code for java.awt.Menu definition code for java.awt.Menu  m)
          Adds the specified menu to the menu bar.
 void addNotify sample code for java.awt.MenuBar.addNotify() definition code for java.awt.MenuBar.addNotify() ()
          Creates the menu bar's peer.
 int countMenus sample code for java.awt.MenuBar.countMenus() definition code for java.awt.MenuBar.countMenus() ()
          Deprecated. As of JDK version 1.1, replaced by getMenuCount().
 void deleteShortcut sample code for java.awt.MenuBar.deleteShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuBar.deleteShortcut(java.awt.MenuShortcut) (MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
          Deletes the specified menu shortcut.
 AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.AccessibleContext getAccessibleContext sample code for java.awt.MenuBar.getAccessibleContext() definition code for java.awt.MenuBar.getAccessibleContext() ()
          Gets the AccessibleContext associated with this MenuBar.
 Menu sample code for java.awt.Menu definition code for java.awt.Menu getHelpMenu sample code for java.awt.MenuBar.getHelpMenu() definition code for java.awt.MenuBar.getHelpMenu() ()
          Gets the help menu on the menu bar.
 Menu sample code for java.awt.Menu definition code for java.awt.Menu getMenu sample code for java.awt.MenuBar.getMenu(int) definition code for java.awt.MenuBar.getMenu(int) (int i)
          Gets the specified menu.
 int getMenuCount sample code for java.awt.MenuBar.getMenuCount() definition code for java.awt.MenuBar.getMenuCount() ()
          Gets the number of menus on the menu bar.
 MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem getShortcutMenuItem sample code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut) definition code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut) (MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.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.
 void remove sample code for java.awt.MenuBar.remove(int) definition code for java.awt.MenuBar.remove(int) (int index)
          Removes the menu located at the specified index from this menu bar.
 void remove sample code for java.awt.MenuBar.remove(java.awt.MenuComponent) definition code for java.awt.MenuBar.remove(java.awt.MenuComponent) (MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent  m)
          Removes the specified menu component from this menu bar.
 void removeNotify sample code for java.awt.MenuBar.removeNotify() definition code for java.awt.MenuBar.removeNotify() ()
          Removes the menu bar's peer.
 void setHelpMenu sample code for java.awt.MenuBar.setHelpMenu(java.awt.Menu) definition code for java.awt.MenuBar.setHelpMenu(java.awt.Menu) (Menu sample code for java.awt.Menu definition code for java.awt.Menu  m)
          Sets the specified menu to be this menu bar's help menu.
 Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut > shortcuts sample code for java.awt.MenuBar.shortcuts() definition code for java.awt.MenuBar.shortcuts() ()
          Gets an enumeration of all menu shortcuts this menu bar is managing.
 
Methods inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
dispatchEvent sample code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) , getFont sample code for java.awt.MenuComponent.getFont() definition code for java.awt.MenuComponent.getFont() , getName sample code for java.awt.MenuComponent.getName() definition code for java.awt.MenuComponent.getName() , getParent sample code for java.awt.MenuComponent.getParent() definition code for java.awt.MenuComponent.getParent() , getPeer sample code for java.awt.MenuComponent.getPeer() definition code for java.awt.MenuComponent.getPeer() , getTreeLock sample code for java.awt.MenuComponent.getTreeLock() definition code for java.awt.MenuComponent.getTreeLock() , paramString sample code for java.awt.MenuComponent.paramString() definition code for java.awt.MenuComponent.paramString() , postEvent sample code for java.awt.MenuComponent.postEvent(java.awt.Event) definition code for java.awt.MenuComponent.postEvent(java.awt.Event) , processEvent sample code for java.awt.MenuComponent.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuComponent.processEvent(java.awt.AWTEvent) , setFont sample code for java.awt.MenuComponent.setFont(java.awt.Font) definition code for java.awt.MenuComponent.setFont(java.awt.Font) , setName sample code for java.awt.MenuComponent.setName(java.lang.String) definition code for java.awt.MenuComponent.setName(java.lang.String) , toString sample code for java.awt.MenuComponent.toString() definition code for java.awt.MenuComponent.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 
Methods inherited from interface java.awt.MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer
getFont sample code for java.awt.MenuContainer.getFont() definition code for java.awt.MenuContainer.getFont() , postEvent sample code for java.awt.MenuContainer.postEvent(java.awt.Event) definition code for java.awt.MenuContainer.postEvent(java.awt.Event)
 

Constructor Detail

MenuBar sample code for java.awt.MenuBar() definition code for java.awt.MenuBar()

public MenuBar()
        throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Creates a new menu bar.

Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()
Method Detail

addNotify sample code for java.awt.MenuBar.addNotify() definition code for java.awt.MenuBar.addNotify()

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.


removeNotify sample code for java.awt.MenuBar.removeNotify() definition code for java.awt.MenuBar.removeNotify()

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.

Overrides:
removeNotify sample code for java.awt.MenuComponent.removeNotify() definition code for java.awt.MenuComponent.removeNotify() in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent

getHelpMenu sample code for java.awt.MenuBar.getHelpMenu() definition code for java.awt.MenuBar.getHelpMenu()

public Menu sample code for java.awt.Menu definition code for java.awt.Menu  getHelpMenu()
Gets the help menu on the menu bar.

Returns:
the help menu on this menu bar.

setHelpMenu sample code for java.awt.MenuBar.setHelpMenu(java.awt.Menu) definition code for java.awt.MenuBar.setHelpMenu(java.awt.Menu)

public void setHelpMenu(Menu sample code for java.awt.Menu definition code for java.awt.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

add sample code for java.awt.MenuBar.add(java.awt.Menu) definition code for java.awt.MenuBar.add(java.awt.Menu)

public Menu sample code for java.awt.Menu definition code for java.awt.Menu  add(Menu sample code for java.awt.Menu definition code for java.awt.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) sample code for java.awt.MenuBar.remove(int) definition code for java.awt.MenuBar.remove(int) , remove(java.awt.MenuComponent) sample code for java.awt.MenuBar.remove(java.awt.MenuComponent) definition code for java.awt.MenuBar.remove(java.awt.MenuComponent)

remove sample code for java.awt.MenuBar.remove(int) definition code for java.awt.MenuBar.remove(int)

public 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) sample code for java.awt.MenuBar.add(java.awt.Menu) definition code for java.awt.MenuBar.add(java.awt.Menu)

remove sample code for java.awt.MenuBar.remove(java.awt.MenuComponent) definition code for java.awt.MenuBar.remove(java.awt.MenuComponent)

public void remove(MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent  m)
Removes the specified menu component from this menu bar.

Specified by:
remove sample code for java.awt.MenuContainer.remove(java.awt.MenuComponent) definition code for java.awt.MenuContainer.remove(java.awt.MenuComponent) in interface MenuContainer sample code for java.awt.MenuContainer definition code for java.awt.MenuContainer
Parameters:
m - the menu component to be removed.
See Also:
add(java.awt.Menu) sample code for java.awt.MenuBar.add(java.awt.Menu) definition code for java.awt.MenuBar.add(java.awt.Menu)

getMenuCount sample code for java.awt.MenuBar.getMenuCount() definition code for java.awt.MenuBar.getMenuCount()

public int getMenuCount()
Gets the number of menus on the menu bar.

Returns:
the number of menus on the menu bar.
Since:
JDK1.1

countMenus sample code for java.awt.MenuBar.countMenus() definition code for java.awt.MenuBar.countMenus()

@Deprecated
public int countMenus()
Deprecated. As of JDK version 1.1, replaced by getMenuCount().


getMenu sample code for java.awt.MenuBar.getMenu(int) definition code for java.awt.MenuBar.getMenu(int)

public Menu sample code for java.awt.Menu definition code for java.awt.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.

shortcuts sample code for java.awt.MenuBar.shortcuts() definition code for java.awt.MenuBar.shortcuts()

public Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.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:
JDK1.1
See Also:
MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut

getShortcutMenuItem sample code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut) definition code for java.awt.MenuBar.getShortcutMenuItem(java.awt.MenuShortcut)

public MenuItem sample code for java.awt.MenuItem definition code for java.awt.MenuItem  getShortcutMenuItem(MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.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 sample code for java.awt.MenuItem definition code for java.awt.MenuItem , MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut

deleteShortcut sample code for java.awt.MenuBar.deleteShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuBar.deleteShortcut(java.awt.MenuShortcut)

public void deleteShortcut(MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
Deletes the specified menu shortcut.

Parameters:
s - the menu shortcut to delete.
Since:
JDK1.1

getAccessibleContext sample code for java.awt.MenuBar.getAccessibleContext() definition code for java.awt.MenuBar.getAccessibleContext()

public AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.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:
getAccessibleContext sample code for javax.accessibility.Accessible.getAccessibleContext() definition code for javax.accessibility.Accessible.getAccessibleContext() in interface Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible
Overrides:
getAccessibleContext sample code for java.awt.MenuComponent.getAccessibleContext() definition code for java.awt.MenuComponent.getAccessibleContext() in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
Returns:
an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar