所有类


javax.swing
类 JMenuItem

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.AbstractButton
                  继承者 javax.swing.JMenuItem
所有已实现的接口:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
直接已知子类:
JCheckBoxMenuItem, JMenu, JRadioButtonMenuItem

public class JMenuItem
   
   
   
   
   
extends AbstractButton
implements Accessible, MenuElement

菜单中的项的实现。菜单项本质上是位于列表中的按钮。当用户选择“按钮”时,将执行与菜单项关联的操作。JPopupMenu 中包含的 JMenuItem 正好执行该功能。

有关更多文档和示例,请参见《The Java Tutorial》中的 How to Use Menus 一节。

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

另请参见:
JPopupMenu, JMenu, JCheckBoxMenuItem, JRadioButtonMenuItem

嵌套类摘要
protected  class JMenuItem.AccessibleJMenuItem
          此类实现 JMenuItem 类的可访问性支持。
 
从类 javax.swing.AbstractButton 继承的嵌套类/接口
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.AbstractButton 继承的字段
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
从类 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
 
从接口 javax.swing.SwingConstants 继承的字段
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JMenuItem()
          创建不带有设置文本或图标的 JMenuItem
JMenuItem(Action a)
          创建一个从指定的 Action 获取其属性的菜单项。
JMenuItem(Icon icon)
          创建带有指定图标的 JMenuItem
JMenuItem(String text)
          创建带有指定文本的 JMenuItem
JMenuItem(String text, Icon icon)
          创建带有指定文本和图标的 JMenuItem
JMenuItem(String text, int mnemonic)
          创建带有指定文本和键盘助记符的 JMenuItem
 
方法摘要
 void addMenuDragMouseListener(MenuDragMouseListener l)
          将 MenuDragMouseListener 添加到菜单项。
 void addMenuKeyListener(MenuKeyListener l)
          将 MenuKeyListener 添加到菜单项。
protected  void configurePropertiesFromAction(Action a)
          该工厂方法根据 Action 实例的值设置 ActionEvent 源的属性。
protected  PropertyChangeListener createActionPropertyChangeListener(Action a)
          该工厂方法在 ActionEventAction 实例上的属性发生更改时创建用于更新 ActionEvent 源的 PropertyChangeListener
protected  void fireMenuDragMouseDragged(MenuDragMouseEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuDragMouseEntered(MenuDragMouseEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuDragMouseExited(MenuDragMouseEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuDragMouseReleased(MenuDragMouseEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuKeyPressed(MenuKeyEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuKeyReleased(MenuKeyEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
protected  void fireMenuKeyTyped(MenuKeyEvent event)
          通知所有对此事件类型上的通知感兴趣的已注册侦听器。
 KeyStroke getAccelerator()
          返回作为菜单项的加速器的 KeyStroke
 AccessibleContext getAccessibleContext()
          返回与此 JMenuItem 相关的 AccessibleContext
 Component getComponent()
          返回用于绘制此对象的 java.awt.Component
 MenuDragMouseListener[] getMenuDragMouseListeners()
          返回利用 addMenuDragMouseListener() 添加到此 JMenuItem 的所有 MenuDragMouseListener 组成的数组。
 MenuKeyListener[] getMenuKeyListeners()
          返回利用 addMenuKeyListener() 添加到此 JMenuItem 的所有 MenuKeyListener 的数组。
 MenuElement[] getSubElements()
          此方法返回包含此菜单组件的子菜单组件的数组。
 String getUIClassID()
          返回用于构造呈现此组件时使用的 L&F 类名称的后缀。
protected  void init(String text, Icon icon)
          利用指定文本和图标初始化菜单项。
 boolean isArmed()
          返回菜单项是否被“调出”。
 void menuSelectionChanged(boolean isIncluded)
          当选择或取消选择 MenuElement 时由 MenuSelectionManager 调用。
protected  String paramString()
          返回此 JMenuItem 的字符串表示形式。
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
          通过使用 MenuSelectionManager 的 API 处理从 MenuSelectionManager 转发的键事件,并在需要时更改菜单选择。
 void processMenuDragMouseEvent(MenuDragMouseEvent e)
          处理菜单中的鼠标拖动。
 void processMenuKeyEvent(MenuKeyEvent e)
          处理菜单中的快捷键。
 void processMouseEvent(MouseEvent e, MenuElement[] path, MenuSelectionManager manager)
          通过使用 MenuSelectionManager 的 API 处理从 MenuSelectionManager 转发的鼠标事件,并在需要时更改菜单选择。
 void removeMenuDragMouseListener(MenuDragMouseListener l)
          从菜单项中移除 MenuDragMouseListener
 void removeMenuKeyListener(MenuKeyListener l)
          从菜单项中移除 MenuKeyListener
 void setAccelerator(KeyStroke keyStroke)
          设置组合键,它能直接调用菜单项的操作侦听器而不必显示菜单的层次结构。
 void setArmed(boolean b)
          将菜单项标识为“调出”。
 void setEnabled(boolean b)
          启用或禁用菜单项。
 void setUI(MenuItemUI ui)
          设置呈现此组件的外观对象。
 void updateUI()
          利用当前外观的值重置 UI 属性。
 
从类 javax.swing.AbstractButton 继承的方法
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, 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, 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, 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
 

构造方法详细信息

JMenuItem

public JMenuItem()
创建不带有设置文本或图标的 JMenuItem


JMenuItem

public JMenuItem(Icon icon)
创建带有指定图标的 JMenuItem

参数:
icon - JMenuItem 的图标

JMenuItem

public JMenuItem(String text)
创建带有指定文本的 JMenuItem

参数:
text - JMenuItem 的文本

JMenuItem

public JMenuItem(Action a)
创建一个从指定的 Action 获取其属性的菜单项。

参数:
a - JMenuItem 的操作
从以下版本开始:
1.3

JMenuItem

public JMenuItem(String text,
                 Icon icon)
创建带有指定文本和图标的 JMenuItem

参数:
text - JMenuItem 的文本
icon - JMenuItem 图标

JMenuItem

public JMenuItem(String text,
                 int mnemonic)
创建带有指定文本和键盘助记符的 JMenuItem

参数:
text - JMenuItem 的文本
mnemonic - JMenuItem 的键盘助记符
方法详细信息

init

protected void init(String text,
                    Icon icon)
利用指定文本和图标初始化菜单项。

覆盖:
AbstractButton 中的 init
参数:
text - JMenuItem 的文本
icon - JMenuItem 图标

setUI

public void setUI(MenuItemUI ui)
设置呈现此组件的外观对象。

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

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部