- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JMenuBar
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,MenuElement
- Direct Known Subclasses:
BasicInternalFrameTitlePane.SystemMenuBar
@JavaBean(defaultProperty="UI", description="A container for holding and displaying menus.") public class JMenuBar extends JComponent implements Accessible, MenuElement
An implementation of a menu bar. You addJMenu
objects to the menu bar to construct a menu. When the user selects aJMenu
object, its associatedJPopupMenu
is displayed, allowing the user to select one of theJMenuItems
on it.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 seeXMLEncoder
.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 thefocusTraversalKeysEnabled
property ofJMenuBar
is set tofalse
. To resolve this, you should call theJMenuBar.setFocusTraversalKeysEnabled(true)
method.- Since:
- 1.2
- See Also:
JMenu
,JPopupMenu
,JMenuItem
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
JMenuBar.AccessibleJMenuBar
This class implements accessibility support for theJMenuBar
class.-
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
-
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description JMenuBar()
Creates a new menu bar.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JMenu
add(JMenu c)
Appends the specified menu to the end of the menu bar.void
addNotify()
OverridesJComponent.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 aMenuElement
.Component
getComponentAtIndex(int i)
Deprecated.replaced bygetComponent(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 aMenuElement
-- 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 aMenuElement
-- does nothing.protected void
paintBorder(Graphics g)
Paints the menubar's border ifBorderPainted
property is true.protected String
paramString()
Returns a string representation of thisJMenuBar
.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 aMenuElement
-- does nothing.void
processMouseEvent(MouseEvent event, MenuElement[] path,
-