#

| Chapter 19 java.awt Reference |

# MenuBar

## Name

MenuBar

##

## Description

A `MenuBar` holds menus. `MenuBar`s are always attached to frames, and displayed on the top line of the `Frame`. One menu in a `MenuBar` may be designated a "help" menu.

## Class Definition

    public class java.awt.MenuBar
        extends java.awt.MenuComponent
        implements java.awt.MenuContainer {

      // Constructors
      public MenuBar();

      // Instance Methods
      public synchronized Menu add (Menu m);
      public void addNotify();
      public int countMenus();
      public void deleteShortcut (MenuShortcut s);
      public Menu getHelpMenu();
      public Menu getMenu (int index);
      public int getMenuCount();
      public MenuItem getShortcutMenuItem (MenuShortcut s);
      public synchronized void remove (int index);
      public synchronized void remove (MenuComponent component);
      public void removeNotify();
      public synchronized void setHelpMenu (Menu m);
      public synchronized Enumeration shortcuts();
    }

## Constructors

### MenuBar

#### public MenuBar()

Description

  Constructs a `MenuBar` object.

## Instance Methods

### add

#### public synchronized Menu add (Menu m)

Parameters

  m

    A `Menu` to add to `MenuBar`.

Returns

  Item just added.

Description

  Adds a new menu to the `MenuBar`.

### addNotify

#### public void addNotify()

Description

  Creates `MenuBar`'s peer and peers of contained menus.

### countMenus

#### public int countMenus()

Returns

  The number of menus on the menu bar. Replaced by `getMenuCount()`.

### deleteShortcut

#### public void deleteShortcut (MenuShortcut s)

Parameters

  s

    The shortcut to remove.

Description

  Removes a menu shortcut.

### getHelpMenu

#### public Menu getHelpMenu()

Returns

  The menu that was designated the help menu.

### getMenu

#### public Menu getMenu (int index)

Parameters

  index

    The position of the `Menu` to fetch.

Returns

  The `Menu` at the designated position.

### getMenuCount

#### public int getMenuCount()

Returns

  The number of menus on the menu bar.

### getShortcutMenuItem

#### public MenuItem getShortcutMenuItem (MenuShortcut s)

Parameters

  s

    A menu shortcut.

Returns

  The corresponding menu item.

Description

  Finds the `MenuItem` corresponding to the given `MenuShortcut`, or `null` if no match is found.

### remove

#### public synchronized void remove (int index)

Parameters

  index

    The position of the `Menu` to remove.

Description

  Removes a `Menu` from the `MenuBar`.

#### public synchronized void remove (MenuComponent component)

Parameters

  component

    The element of the `MenuBar` to remove.

Implements

  `MenuContainer.remove()`

Description

  Removes a `Menu` from the `MenuBar`.

### removeNotify

#### public void removeNotify()

Description

  Destroys the `MenuBar` peer, and peers for all `Menu` objects that appear on it.

### setHelpMenu

#### public synchronized void setHelpMenu (Menu m)

Parameters

  m

    `Menu` to designate as the help menu.

Description

  Designates a `Menu` as the `MenuBar`'s help menu.

### shortcuts

#### public synchronized Enumeration shortcuts()

Returns

  An `Enumeration` of `MenuShortcut` objects.

Description

  Returns an `Enumeration` of all `MenuShortcut` objects managed by this `MenuBar`.

## See Also

`Frame`, `Menu`, `MenuComponent`, `MenuContainer`

Menu |  | MenuComponent