public class MenuBar extends MenuComponentimplements MenuContainer , Accessible
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, shortcuts() and getShortcutMenuItem(java.awt.MenuShortcut) that retrieve information about the shortcuts a given menu bar is managing.
Frame,
Frame.setMenuBar(java.awt.MenuBar) ,
Menu,
MenuItem,
MenuShortcut,
Serialized Form
| Modifier and Type | Class and Description |
|---|---|
protected class |
MenuBar
Inner class of MenuBar used to provide default support for accessibility.
|
MenuComponent.AccessibleAWTMenuComponent | Constructor and Description |
|---|
MenuBar()
Creates a new menu bar.
|
| Modifier and Type | Method and Description |
|---|---|
Menu |
add(Menu
Adds the specified menu to the menu bar.
|
void |
addNotify()
Creates the menu bar's peer.
|
int |
countMenus()
Deprecated.
As of JDK version 1.1, replaced by
getMenuCount().
|
void |
deleteShortcut(MenuShortcut
Deletes the specified menu shortcut.
|
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this MenuBar.
|
Menu |
getHelpMenu()
Gets the help menu on the menu bar.
|
Menu |
getMenu(int i)
Gets the specified menu.
|
int |
getMenuCount()
Gets the number of menus on the menu bar.
|
MenuItem |
getShortcutMenuItem(MenuShortcut
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 |
remove(MenuComponent
Removes the specified menu component from this menu bar.
|
void |
removeNotify()
Removes the menu bar's peer.
|
void |
setHelpMenu(Menu
Sets the specified menu to be this menu bar's help menu.
|
Enumeration |
shortcuts()
Gets an enumeration of all menu shortcuts this menu bar is managing.
|
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetFont, postEventpublic MenuBar()
throws HeadlessException
HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
GraphicsEnvironment.isHeadless()
public void addNotify()
public void removeNotify()
public MenugetHelpMenu()
public void setHelpMenu(Menum)
m - the menu to be set as the help menu
public Menuadd(Menu m)
m - the menu to be added
remove(int),
remove(java.awt.MenuComponent)
public void remove(int index)
index - the position of the menu to be removed.
add(java.awt.Menu)
public void remove(MenuComponentm)
remove in interface
MenuContainer
m - the menu component to be removed.
add(java.awt.Menu)
public int getMenuCount()
@Deprecated public int countMenus()
getMenuCount().
public MenugetMenu(int i)
i - the index position of the menu to be returned.
public Enumeration<MenuShortcut > shortcuts()
MenuShortcut
public MenuItemgetShortcutMenuItem(MenuShortcut s)
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.
s - the specified menu shortcut.
MenuItem,
MenuShortcut
public void deleteShortcut(MenuShortcuts)
s - the menu shortcut to delete.
public AccessibleContextgetAccessibleContext()
getAccessibleContext in interface
Accessible
getAccessibleContext in class
MenuComponent