java.awt

Class MenuBar

public class MenuBar extends MenuComponent implements MenuContainer, Serializable, Accessible

This class implements a menu bar in the AWT system.
Nested Class Summary
protected classMenuBar.AccessibleAWTMenuBar
This class provides accessibility support for AWT menu bars.
Constructor Summary
MenuBar()
Initializes a new instance of MenuBar.
Method Summary
Menuadd(Menu menu)
Add a menu to this MenuBar.
voidaddNotify()
Creates this object's native peer.
intcountMenus()
Returns the number of elements in this menu bar.
voiddeleteShortcut(MenuShortcut shortcut)
Deletes the specified menu shortcut.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this MenuBar.
MenugetHelpMenu()
Returns the help menu for this menu bar.
MenugetMenu(int index)
Returns the menu at the specified index.
intgetMenuCount()
Returns the number of elements in this menu bar.
MenuItemgetShortcutMenuItem(MenuShortcut shortcut)
Returns the menu item for the specified shortcut, or null if no such item exists.
voidremove(int index)
Removes the menu at the specified index.
voidremove(MenuComponent menu)
Removes the specified menu from the menu bar.
voidremoveNotify()
Destroys this object's native peer.
voidsetHelpMenu(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.

Constructor Detail

MenuBar

public MenuBar()
Initializes a new instance of MenuBar.

Throws: HeadlessException if GraphicsEnvironment.isHeadless() is true

Method Detail

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

addNotify

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

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

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.

Returns: the associated context

getHelpMenu

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

Returns: the help menu for this 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

getMenuCount

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

Returns: the number of elements in the 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

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.

Parameters: menu the menu to remove from the menu bar

removeNotify

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

setHelpMenu

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

Parameters: menu the new help menu for this menu bar

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