javax.swing

接口
异常
java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JMenuBar
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, MenuElement
直接已知子类:
BasicInternalFrameTitlePane.SystemMenuBar

public class JMenuBar
     
extends JComponent
implements Accessible, MenuElement

菜单栏的实现。将 JMenu 对象添加到菜单栏以构造菜单。当用户选择 JMenu 对象时,就会显示其关联的 JPopupMenu,允许用户选择其上的某一个 JMenuItem

有关使用菜单栏的信息和示例,请参阅 The Java Tutorial 中的 How to Use Menus 一节。

警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
JMenu, JPopupMenu, JMenuItem

嵌套类摘要
protected  class JMenuBar.AccessibleJMenuBar
          此类实现 JMenuBar 类的可访问性支持。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JMenuBar()
          创建新的菜单栏。
 
方法摘要
 JMenu add(JMenu c)
          将指定的菜单追加到菜单栏的末尾。
 void addNotify()
          重写 JComponent.addNotify 以向当前键盘管理器注册此菜单栏。
 AccessibleContext getAccessibleContext()
          获取与此 JMenuBar 相关联的 AccessibleContext。
 Component getComponent()
          实现为 MenuElement
 Component getComponentAtIndex(int i)
          已过时。 getComponent(int i) 取代
 int getComponentIndex(Component c)
          返回指定组件的索引。
 JMenu getHelpMenu()
          获取菜单栏的帮助菜单。
 Insets getMargin()
          返回菜单栏的边框与其菜单之间的空白。
 JMenu getMenu(int index)
          返回菜单栏中指定位置的菜单。
 int getMenuCount()
          返回菜单栏上的菜单数。
 SingleSelectionModel getSelectionModel()
          返回处理单个选择的模型对象。
 MenuElement[] getSubElements()
          实现为 MenuElement(返回此菜单栏中的菜单)。
 MenuBarUI getUI()
          返回菜单栏的当前 UI。
 String getUIClassID()
          返回呈现此组件的 L&F 类的名称。
 boolean isBorderPainted()
          如果应该绘制菜单栏的边框,则返回 true。
 boolean isSelected()
          如果当前已选择了菜单栏的组件,则返回 true。
 void menuSelectionChanged(boolean isIncluded)
          实现为 MenuElement(不执行任何操作)。
protected  void paintBorder(Graphics g)
          如果 BorderPainted 属性为 true,则绘制菜单栏的边框。
protected  String paramString()
          返回此 JMenuBar 的字符串表示形式。
protected  boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
          子类化以检查所有子菜单。
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
          实现为 MenuElement(不执行任何操作)。
 void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
          实现为 MenuElement(不执行任何操作)。
 void removeNotify()
          重写 JComponent.removeNotify 以在当前键盘管理器中注销此菜单栏。
 void setBorderPainted(boolean b)
          设置是否应该绘制边框。
 void setHelpMenu(JMenu menu)
          设置用户选择菜单栏中的“帮助”选项时显示的帮助菜单。
 void setMargin(Insets m)
          设置菜单栏的边框与其菜单之间的空白。
 void setSelected(Component sel)
          设置当前选择的组件,更改选择模型。
 void setSelectionModel(SingleSelectionModel model)
          设置处理单个选择的模型对象。
 void setUI(MenuBarUI ui)
          设置呈现此组件的 L&F 对象。
 void updateUI()
          利用当前外观的值重置 UI 属性。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

JMenuBar

public JMenuBar()
创建新的菜单栏。

方法详细信息

getUI

public MenuBarUI getUI()
返回菜单栏的当前 UI。

另请参见:
setUI(javax.swing.plaf.MenuBarUI)

setUI

public void setUI(MenuBarUI ui)
设置呈现此组件的 L&F 对象。

参数:
ui - 新的 MenuBarUI L&F 对象
另请参见:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
利用当前外观的值重置 UI 属性。

覆盖:
JComponent 中的 updateUI
另请参见:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
返回呈现此组件的 L&F 类的名称。

覆盖:
JComponent 中的 getUIClassID
返回:
字符串 "MenuBarUI"
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

getSelectionModel

public SingleSelectionModel getSelectionModel()
返回处理单个选择的模型对象。

返回:
SingleSelectionModel 属性
另请参见:
SingleSelectionModel

setSelectionModel

public void setSelectionModel(SingleSelectionModel model)
设置处理单个选择的模型对象。

参数:
model - 要使用的 SingleSelectionModel
另请参见:
SingleSelectionModel

JDK 1.6 中文手册