- java.lang.Object
-
- java.awt.MenuComponent
-
- java.awt.MenuBar
-
- All Implemented Interfaces:
- MenuContainer, Serializable, Accessible
public class MenuBar extends MenuComponent implements MenuContainer, Accessible
TheMenuBar
class encapsulates the platform's concept of a menu bar bound to a frame. In order to associate the menu bar with aFrame
object, call the frame'ssetMenuBar
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
. TheMenuBar
class defines several methods,shortcuts()
andgetShortcutMenuItem(java.awt.MenuShortcut)
that retrieve information about the shortcuts a given menu bar is managing.- Since:
- JDK1.0
- See Also:
Frame
,Frame.setMenuBar(java.awt.MenuBar)
,Menu
,MenuItem
,MenuShortcut
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected class
MenuBar.AccessibleAWTMenuBar
Inner class of MenuBar used to provide default support for accessibility.-
Nested classes/interfaces inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
-
-
Constructor Summary
Constructors Constructor and Description MenuBar()
Creates a new menu bar.
-
Method Summary
Methods Modifier and Type Method and Description Menu
add(Menu m)
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 bygetMenuCount()
.void
deleteShortcut(MenuShortcut s)
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 s)
Gets the instance ofMenuItem
associated with the specifiedMenuShortcut
object, ornull
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 m)
Removes the specified menu component from this menu bar.void
removeNotify()
Removes the menu bar's peer.void
setHelpMenu(Menu m)
Sets the specified menu to be this menu bar's help menu.Enumeration<MenuShortcut>
shortcuts()
Gets an enumeration of all menu shortcuts this menu bar is managing.-
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, paramString, postEvent, processEvent, setFont, setName, toString
-
-
-
-
Constructor Detail
-
MenuBar
public MenuBar() throws HeadlessException
Creates a new menu bar.- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
-
Method Detail
-
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:
removeNotify
in classMenuComponent
-
getHelpMenu
public Menu getHelpMenu()
Gets the help menu on the menu bar.- Returns:
- the help menu on this menu bar.
-
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
-
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
- See Also:
remove(int)
,remove(java.awt.MenuComponent)
-
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:
add(java.awt.Menu)
-
remove
public void remove(MenuComponent m)
Removes the specified menu component from this menu bar.- Specified by:
remove
in interfaceMenuContainer
- Parameters:
m
- the menu component to be removed.- See Also:
add(java.awt.Menu)
-
getMenuCount
public int getMenuCount()
Gets the number of menus on the menu bar.- Returns:
- the number of menus on the menu bar.
- Since:
- JDK1.1
-
countMenus
@Deprecated public int countMenus()
Deprecated. As of JDK version 1.1, replaced bygetMenuCount()
.
-
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.
-
shortcuts
public Enumeration<MenuShortcut> 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:
- JDK1.1
- See Also:
MenuShortcut
-
getShortcutMenuItem
public MenuItem getShortcutMenuItem(MenuShortcut s)
Gets the instance ofMenuItem
associated with the specifiedMenuShortcut
object, ornull
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.- Since:
- JDK1.1
- See Also:
MenuItem
,MenuShortcut
-
deleteShortcut
public void deleteShortcut(MenuShortcut s)
Deletes the specified menu shortcut.- Parameters:
s
- the menu shortcut to delete.- Since:
- JDK1.1
-
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.- Specified by:
getAccessibleContext
in interfaceAccessible
- Overrides:
getAccessibleContext
in classMenuComponent
- Returns:
- an AccessibleAWTMenuBar that serves as the AccessibleContext of this MenuBar
- Since:
- 1.3
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/awt/MenuBar.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.