java.awt
Class MenuBar

java.lang.Object
  extended by java.awt.MenuComponent
      extended by java.awt.MenuBar
All Implemented Interfaces:
MenuContainer, Serializable, Accessible

public class MenuBar
extends MenuComponent
implements MenuContainer, Serializable, Accessible

This class implements a menu bar in the AWT system.

See Also:
Serialized Form

Nested Class Summary
protected  class MenuBar.AccessibleAWTMenuBar
          This class provides accessibility support for AWT menu bars.
 
Nested classes/interfaces inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
MenuBar()
          Initializes a new instance of MenuBar.
 
Method Summary
 Menu add(Menu menu)
          Add a menu to this MenuBar.
 void addNotify()
          Creates this object's native peer.
 int countMenus()
          Deprecated. This method is deprecated in favor of getMenuCount().
 void deleteShortcut(MenuShortcut shortcut)
          Deletes the specified menu shortcut.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this MenuBar.
 Menu getHelpMenu()
          Returns the help menu for this menu bar.
 Menu getMenu(int index)
          Returns the menu at the specified index.
 int getMenuCount()
          Returns the number of elements in this menu bar.
 MenuItem getShortcutMenuItem(MenuShortcut shortcut)
          Returns the menu item for the specified shortcut, or null if no such item exists.
 void remove(int index)
          Removes the menu at the specified index.
 void remove(MenuComponent menu)
          Removes the specified menu from the menu bar.
 void removeNotify()
          Destroys this object's native peer.
 void setHelpMenu(Menu menu)
          Sets the help menu for this menu bar.
 Enumeration<MenuShortcut> shortcuts()
          Returns a list of all shortcuts for the menus in this menu bar.
 
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
 

Constructor Detail

MenuBar

public MenuBar()
Initializes a new instance of MenuBar.

Throws:
HeadlessException - if GraphicsEnvironment.isHeadless() is true
Method Detail

getHelpMenu

public Menu getHelpMenu()
Returns the help menu for this menu bar. This may be null.

Returns:
the help menu for this menu bar

setHelpMenu

public void setHelpMenu(Menu menu)
Sets the help menu for this menu bar.

Parameters:
menu - the new help menu for this menu bar

add

public Menu add(Menu menu)
Add a menu to this MenuBar. If the menu has already has a parent, it is first removed from its old parent before being added.

Parameters:
menu - the menu to add
Returns:
the menu that was added

remove

public void remove(int index)
Removes the menu at the specified index.

Parameters:
index - the index of the menu to remove from the menu bar

remove

public void remove(MenuComponent menu)
Removes the specified menu from the menu bar.

Specified by:
remove in interface MenuContainer
Parameters:
menu - the menu to remove from the menu bar

getMenuCount

public int getMenuCount()
Returns the number of elements in this menu bar.

Returns:
the number of elements in the menu bar

countMenus

public int countMenus()
Deprecated. This method is deprecated in favor of getMenuCount().

Returns the number of elements in this menu bar.

Returns:
the number of elements in the menu bar

getMenu

public Menu getMenu(int index)
Returns the menu at the specified index.

Parameters:
index - the index of the menu
Returns:
the requested menu
Throws:
ArrayIndexOutOfBoundsException - if the index is not valid

addNotify

public void addNotify()
Creates this object's native peer.


removeNotify

public void removeNotify()
Destroys this object's native peer.

Overrides:
removeNotify in class MenuComponent

shortcuts

public Enumeration<MenuShortcut> shortcuts()
Returns a list of all shortcuts for the menus in this menu bar.

Returns:
a list of all shortcuts for the menus in this menu bar

getShortcutMenuItem

public MenuItem getShortcutMenuItem(MenuShortcut shortcut)
Returns the menu item for the specified shortcut, or null if no such item exists.

Parameters:
shortcut - the shortcut to return the menu item for
Returns:
the menu item for the specified shortcut

deleteShortcut

public void deleteShortcut(MenuShortcut shortcut)
Deletes the specified menu shortcut.

Parameters:
shortcut - the shortcut to delete

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this MenuBar. The context is created, if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class MenuComponent
Returns:
the associated context