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.
java.awt.Frame , java.awt.Frame#setMenuBar(java.awt.MenuBar) , java.awt.Menu , java.awt.MenuItem , java.awt.MenuShortcut
| Modifier and Type | Class and Description |
|---|---|
| protected class | MenuBar.
Inner class of MenuBar used to provide default support for accessibility. |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private volatile Menu | helpMenu
This menu is a special menu dedicated to help. |
| private int | menuBarSerializedDataVersion
The MenuBar's serialized data version. |
| private final Vector | menus
This field represents a vector of the actual menus that will be part of the MenuBar. |
| private static int | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Menu | |
| public void | |
| pack-priv String | constructComponentName()
Overrides java. Construct a name for this MenuComponent. |
| public int | Returns: the number of menus on the menu bar.
Deprecated
As of JDK version 1.1,
replaced by
getMenuCount().
Gets the number of menus on the menu bar. |
| public void | |
| pack-priv int | getAccessibleChildIndex(MenuComponent child)
Overrides java. Defined in MenuComponent. |
| public AccessibleContext | Returns: an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBarOverrides java. Implements javax. Gets the AccessibleContext associated with this MenuBar. |
| public Menu | |
| public Menu | Returns: the menu at the specified index of this menu bar.the index position of the menu to be returned. i)Gets the specified menu. |
| public int | Returns: the number of menus on the menu bar.Gets the number of menus on the menu bar. |
| pack-priv final int | |
| pack-priv final Menu | |
| public MenuItem | Returns: the menu item for the specified shortcut.the specified menu shortcut. s)Gets the instance of |
| pack-priv boolean | |
| private static native void | |
| private void | readObject(ObjectInputStream
the s)ObjectInputStream to readHides java. Reads the |
| public void | remove(final int
the position of the menu to be removed. index)Removes the menu located at the specified index from this menu bar. |
| public void | remove(MenuComponent
the menu component to be removed. m)Implements java. Removes the specified menu component from this menu bar. |
| public void | |
| public void | setHelpMenu(final Menu
the menu to be set as the help menu m)Sets the specified menu to be this menu bar's help menu. |
| public synchronized Enumeration | Returns: an enumeration of menu shortcuts that this menu bar is managing.Gets an enumeration of all menu shortcuts this menu bar is managing. |
| private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites default serializable fields to stream. |
| base | back to summary |
|---|---|
| private static final String base | |
| helpMenu | back to summary |
|---|---|
| private volatile 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.
| |
| menuBarSerializedDataVersion | back to summary |
|---|---|
| private int menuBarSerializedDataVersion The MenuBar's serialized data version. | |
| menus | back to summary |
|---|---|
| private final Vector<Menu> menus This field represents a vector of the actual menus that will be part of the MenuBar.
| |
| nameCounter | back to summary |
|---|---|
| private static int nameCounter | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. | |
| MenuBar | back to summary |
|---|---|
| public MenuBar() throws HeadlessException Creates a new menu bar.
| |
| add | back to summary |
|---|---|
| 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.
| |
| addNotify | back to summary |
|---|---|
| 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. | |
| constructComponentName | back to summary |
|---|---|
| pack-priv String constructComponentName() Overrides java. Construct a name for this MenuComponent. Called by getName() when the name is null. | |
| countMenus | back to summary |
|---|---|
| public int countMenus()
Deprecated As of JDK version 1.1,
replaced by Gets the number of menus on the menu bar.
| |
| deleteShortcut | back to summary |
|---|---|
| public void deleteShortcut(MenuShortcut s) Deletes the specified menu shortcut.
| |
| getAccessibleChildIndex | back to summary |
|---|---|
| pack-priv int getAccessibleChildIndex(MenuComponent child) Overrides java. Defined in MenuComponent. Overridden here. | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. 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.
| |
| getHelpMenu | back to summary |
|---|---|
| public Menu getHelpMenu() Gets the help menu on the menu bar.
| |
| getMenu | back to summary |
|---|---|
| public Menu getMenu(int i) Gets the specified menu.
| |
| getMenuCount | back to summary |
|---|---|
| public int getMenuCount() Gets the number of menus on the menu bar.
| |
| getMenuCountImpl | back to summary |
|---|---|
| pack-priv final int getMenuCountImpl() | |
| getMenuImpl | back to summary |
|---|---|
| pack-priv final Menu getMenuImpl(int i) | |
| getShortcutMenuItem | back to summary |
|---|---|
| public MenuItem getShortcutMenuItem(MenuShortcut s) Gets the instance of
| |
| handleShortcut | back to summary |
|---|---|
| pack-priv boolean handleShortcut(KeyEvent e) | |
| initIDs | back to summary |
|---|---|
| private static native void initIDs() Initialize JNI field and method IDs | |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException Hides java. Reads the
| |
| remove | back to summary |
|---|---|
| public void remove(final int index) Removes the menu located at the specified index from this menu bar.
| |
| remove | back to summary |
|---|---|
| public void remove(MenuComponent m) Implements java. Removes the specified menu component from this menu bar.
| |
| removeNotify | back to summary |
|---|---|
| public void removeNotify() Overrides java. 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. | |
| setHelpMenu | back to summary |
|---|---|
| public void setHelpMenu(final 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.
| |
| shortcuts | back to summary |
|---|---|
| public synchronized Enumeration Gets an enumeration of all menu shortcuts this menu bar is managing.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Writes default serializable fields to stream.
| |
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.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides java. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides java. Get the role of this object. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.3 for interoperability. | |
| AccessibleAWTMenuBar | back to summary |
|---|---|
| protected AccessibleAWTMenuBar() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides java. Get the role of this object.
| |