For information and examples of using menu bars see How to Use Menus, a section in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
Warning: By default, pressing the Tab key does not transfer focus from a JMenuBar which is added to a container together with other Swing components, because the focusTraversalKeysEnabled property of JMenuBar is set to false. To resolve this, you should call the JMenuBar.setFocusTraversalKeysEnabled(true) method.
| protected class | JMenuBar.AccessibleJMenuBar
This class implements accessibility support for the
JMenuBar class.
|
|
Creates a new menu bar.
|
| JMenu | add(JMenu c)
Appends the specified menu to the end of the menu bar.
|
| void | addNotify()
Overrides JComponent.addNotify to register this
menu bar with the current keyboard manager.
|
| AccessibleContext | getAccessibleContext()
Gets the AccessibleContext associated with this JMenuBar.
|
| Component | getComponent()
Implemented to be a MenuElement.
|
| Component | getComponentAtIndex(int i)
Deprecated.
replaced by getComponent(int i)
|
| int | getComponentIndex(Component c)
Returns the index of the specified component.
|
| JMenu | getHelpMenu()
Gets the help menu for the menu bar.
|
| Insets | getMargin()
Returns the margin between the menubar's border and
its menus.
|
| JMenu | getMenu(int index)
Returns the menu at the specified position in the menu bar.
|
| int | getMenuCount()
Returns the number of items in the menu bar.
|
| SingleSelectionModel | getSelectionModel()
Returns the model object that handles single selections.
|
| MenuElement[] | getSubElements()
Implemented to be a MenuElement -- returns the
menus in this menu bar.
|
| MenuBarUI | getUI()
Returns the menubar's current UI.
|
| String | getUIClassID()
Returns the name of the L&F class that renders this component.
|
| boolean | isBorderPainted()
Returns true if the menu bars border should be painted.
|
| boolean | isSelected()
Returns true if the menu bar currently has a component selected.
|
| void | menuSelectionChanged(boolean isIncluded)
Implemented to be a MenuElement -- does nothing.
|
| protected void | paintBorder(Graphics g)
Paints the menubar's border if BorderPainted
property is true.
|
| protected String | paramString()
Returns a string representation of this JMenuBar.
|
| protected boolean | processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
Subclassed to check all the child menus.
|
| void | processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
Implemented to be a MenuElement -- does nothing.
|
| void | processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
Implemented to be a MenuElement -- does nothing.
|
| void | removeNotify()
Overrides JComponent.removeNotify to unregister this
menu bar with the current keyboard manager.
|
| void | setBorderPainted(boolean b)
Sets whether the border should be painted.
|
| void | setHelpMenu(JMenu menu)
Sets the help menu that appears when the user selects the
"help" option in the menu bar.
|
| void | setMargin(Insets m)
Sets the margin between the menubar's border and
its menus.
|
| void | setSelected(Component sel)
Sets the currently selected component, producing a
a change to the selection model.
|
| void | setSelectionModel(SingleSelectionModel model)
Sets the model object to handle single selections.
|
| void | setUI(MenuBarUI ui)
Sets the L&F object that renders this component.
|
| void | updateUI()
Resets the UI property with a value from the current look and feel.
|
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.