This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt
class MenuBar

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

Most common way to construct:

MenuBar mb = new MenuBar();

Based on 83 examples


public class MenuBar
extends MenuComponent
implements MenuContainer, 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:

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, {@link MenuBar#shortcuts} and {@link MenuBar#getShortcutMenuItem} that retrieve information about the shortcuts a given menu bar is managing.


Nested Class Summary
protected class

           Inner class of MenuBar used to provide default support for accessibility.
Nested classes/interfaces inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
   
Constructor Summary

          Creates a new menu bar.
 
Method Summary
 Menu
add(Menu m)

          Adds the specified menu to the menu bar.
 void

          Creates the menu bar's peer.
 int

          
 void

          Deletes the specified menu shortcut.
 AccessibleContext

          Gets the AccessibleContext associated with this MenuBar.
 Menu

          Gets the help menu on the menu bar.
 Menu
getMenu(int i)

          Gets the specified menu.
 int

          Gets the number of menus on the menu bar.
 MenuItem

          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(int index)

          Removes the menu located at the specified index from this menu bar.
 void

          Removes the specified menu component from this menu bar.
 void

          Removes the menu bar's peer.
 void

          Sets the specified menu to be this menu bar's help menu.
 Enumeration

          Gets an enumeration of all menu shortcuts this menu bar is managing.
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getAccessibleContext, getFont, getName, getParent, getPeer, getTreeLock, paramString, postEvent, processEvent, removeNotify, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBar

public MenuBar()
        throws HeadlessException
Creates a new menu bar.

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

add

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.

Parameters:
m - the menu to be added
Returns:
the menu added

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.


countMenus

public int countMenus()

deleteShortcut

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

Parameters:
s - the menu shortcut to delete.

getAccessibleContext

public 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.

Overrides:
getAccessibleContext in class MenuComponent
Returns:
an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar

getHelpMenu

public Menu getHelpMenu()
Gets the help menu on the menu bar.

Returns:
the help menu on this menu bar.

getMenu

public 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.

getMenuCount

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

Returns:
the number of menus on the menu bar.

getShortcutMenuItem

public MenuItem getShortcutMenuItem(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.

remove

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.

remove

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

Parameters:
m - the menu component to be removed.

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 in class MenuComponent

setHelpMenu

public void setHelpMenu(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

shortcuts

public synchronized Enumeration 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.


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.