Class MenuBar
java.lang.Object
java.awt.MenuComponent
java.awt.MenuBar
- All Implemented Interfaces:
MenuContainer, Serializable, 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,
shortcuts() and
getShortcutMenuItem(MenuShortcut)
that retrieve information about the shortcuts a given
menu bar is managing.
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classInner class of MenuBar used to provide default support for accessibility.Nested classes/interfaces declared in class MenuComponent
MenuComponent.AccessibleAWTMenuComponentModifier and TypeClassDescriptionprotected classInner class ofMenuComponentused to provide default support for accessibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified menu to the menu bar.voidCreates the menu bar's peer.intDeprecated.voidDeletes the specified menu shortcut.Gets the AccessibleContext associated with this MenuBar.Gets the help menu on the menu bar.getMenu(int i) Gets the specified menu.intGets the number of menus on the menu bar.Gets the instance ofMenuItemassociated with the specifiedMenuShortcutobject, ornullif none of the menu items being managed by this menu bar is associated with the specified menu shortcut.voidremove(int index) Removes the menu located at the specified index from this menu bar.voidRemoves the specified menu component from this menu bar.voidRemoves the menu bar's peer.voidsetHelpMenu(Menu m) Sets the specified menu to be this menu bar's help menu.Gets an enumeration of all menu shortcuts this menu bar is managing.Methods declared in class MenuComponent
dispatchEvent, getFont, getName, getParent, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toStringModifier and TypeMethodDescriptionfinal voidDelivers an event to this component or one of its sub components.getFont()Gets the font used for this menu component.getName()Gets the name of the menu component.Returns the parent container for this menu component.protected final ObjectGets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.protected StringReturns a string representing the state of thisMenuComponent.booleanDeprecated.As of JDK version 1.1, replaced bydispatchEvent.protected voidProcesses events occurring on this menu component.voidSets the font to be used for this menu component to the specified font.voidSets the name of the component to the specified string.toString()Returns a representation of this menu component as a string.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
MenuBar
Creates a new menu bar.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
-
Method Details
-
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. -
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:
removeNotifyin classMenuComponent
-
getHelpMenu
Gets the help menu on the menu bar.- Returns:
- the help menu on this menu bar.
-
setHelpMenu
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
-
add
-
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.- See Also:
-
remove
Removes the specified menu component from this menu bar.- Specified by:
removein interfaceMenuContainer- Parameters:
m- the menu component to be removed.- See Also:
-
getMenuCount
public int getMenuCount()Gets the number of menus on the menu bar.- Returns:
- the number of menus on the menu bar.
- Since:
- 1.1
-
countMenus
Deprecated.As of JDK version 1.1, replaced bygetMenuCount().Gets the number of menus on the menu bar.- Returns:
- the number of menus on the menu bar.
-
getMenu
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.
-
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.
- Since:
- 1.1
- See Also:
-
getShortcutMenuItem
Gets the instance ofMenuItemassociated with the specifiedMenuShortcutobject, ornullif none of the menu items being managed by this menu bar is associated with the specified menu shortcut.- Parameters:
s- the specified menu shortcut.- Returns:
- the menu item for the specified shortcut.
- Since:
- 1.1
- See Also:
-
deleteShortcut
Deletes the specified menu shortcut.- Parameters:
s- the menu shortcut to delete.- Since:
- 1.1
-
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.- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classMenuComponent- Returns:
- an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar
- Since:
- 1.3
-
getMenuCount().