JavaTM 2 Platform
Standard Ed. 5.0

javax.swing
类 JCheckBoxMenuItem

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

public class JCheckBoxMenuItem
extends JMenuItem
implements SwingConstants, Accessible

可以被选定或取消选定的菜单项。如果被选定,菜单项的旁边通常会出现一个复选标记。如果未被选定或被取消选定,菜单项的旁边就没有复选标记。像常规菜单项一样,复选框菜单项可以有与之关联的文本或图标,或者二者兼而有之。

isSelected/setSelectedgetState/setState 都可以用来确定/指定菜单项的选择状态。首选方法是 isSelectedsetSelected,它们可用于所有菜单和按钮。getStatesetState 方法用于与其他组件集的兼容性。

有关使用复选框菜单项的更多信息和示例,请参阅《The Java Tutorial》中的 How to Use Menus 一节。

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


嵌套类摘要
protected  class JCheckBoxMenuItem.AccessibleJCheckBoxMenuItem
          此类实现对 JCheckBoxMenuItem 类的可访问性支持。
 
从类 javax.swing.JMenuItem 继承的嵌套类/接口
JMenuItem.AccessibleJMenuItem
 
从类 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
 
构造方法摘要
JCheckBoxMenuItem()
          创建一个没有设置好的文本或图标的、最初未选定的复选框菜单项。
JCheckBoxMenuItem(Action a)
          创建一个从所提供的 Action 中获取其属性的菜单项。
JCheckBoxMenuItem(Icon icon)
          创建有一个图标的、最初未被选定的复选框菜单项。
JCheckBoxMenuItem(String text)
          创建一个带文本的、最初未被选定的复选框菜单项。
JCheckBoxMenuItem(String text, boolean b)
          创建具有指定文本和选择状态的复选框菜单项。
JCheckBoxMenuItem(String text, Icon icon)
          创建带有指定文本和图标的、最初未被选定的复选框菜单项。
JCheckBoxMenuItem(String text, Icon icon, boolean b)
          创建具有指定文本、图标和选择状态的复选框菜单项。
 
方法摘要
 AccessibleContext getAccessibleContext()
          获得与此 JCheckBoxMenuItem 关联的 AccessibleContext。
 Object[] getSelectedObjects()
          返回包含复选框菜单项标签的数组 (length 1),如果没有选定复选框,则返回 null。
 boolean getState()
          返回菜单项的选定状态。
 String getUIClassID()
          返回呈现此组件的 L&F 类的名称。
protected  String paramString()
          返回此 JCheckBoxMenuItem 的字符串表示形式。
 void setState(boolean b)
          设置菜单项的选定状态。
 
从类 javax.swing.JMenuItem 继承的方法
addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getComponent, getMenuDragMouseListeners, getMenuKeyListeners, getSubElements, init, isArmed, menuSelectionChanged, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setAccelerator, setArmed, setEnabled, setUI, updateUI
 
从类 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, 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
 

构造方法详细信息

JCheckBoxMenuItem

public JCheckBoxMenuItem()
创建一个没有设置好的文本或图标的、最初未选定的复选框菜单项。


JCheckBoxMenuItem

public JCheckBoxMenuItem(Icon icon)
创建有一个图标的、最初未被选定的复选框菜单项。

参数:
icon - CheckBoxMenuItem 的图标。

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text)
创建一个带文本的、最初未被选定的复选框菜单项。

参数:
text - CheckBoxMenuItem 的文本

JCheckBoxMenuItem

public JCheckBoxMenuItem(Action a)
创建一个从所提供的 Action 中获取其属性的菜单项。

从以下版本开始:
1.3

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         Icon icon)
创建带有指定文本和图标的、最初未被选定的复选框菜单项。

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

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         boolean b)
创建具有指定文本和选择状态的复选框菜单项。

参数:
text - 复选框菜单项的文本
b - 复选框菜单项的选定状态

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         Icon icon,
                         boolean b)
创建具有指定文本、图标和选择状态的复选框菜单项。

参数:
text - 复选框菜单项的文本
icon - 复选框菜单项的图标
b - 复选框菜单项的选定状态
方法详细信息

getUIClassID

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

覆盖:
JMenuItem 中的 getUIClassID
返回:
"CheckBoxMenuItemUI"
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

getState

public boolean getState()
返回菜单项的选定状态。此方法仅用于 AWT 兼容性。新代码应该使用 isSelected() 作为替代。

返回:
如果该项被选定,则返回 true

setState

public void setState(boolean b)
设置菜单项的选定状态。此方法仅用于 AWT 兼容性。新代码应该使用 setSelected() 作为替代。

参数:
b - 指示项的选定状态的 boolean 值,其中 true = 选定

getSelectedObjects

public Object[] getSelectedObjects()
返回包含复选框菜单项标签的数组 (length 1),如果没有选定复选框,则返回 null。

指定者:
接口 ItemSelectable 中的 getSelectedObjects
覆盖:
AbstractButton 中的 getSelectedObjects
返回:
如果该项被选定,则返回包含一个 Object(菜单项的文本)的数组,否则返回 null

paramString

protected String paramString()
返回此 JCheckBoxMenuItem 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null

覆盖:
JMenuItem 中的 paramString
返回:
a 此 JCheckBoxMenuItem 的字符串表示形式。

getAccessibleContext

public AccessibleContext getAccessibleContext()
获得与此 JCheckBoxMenuItem 关联的 AccessibleContext。对于 JCheckBoxMenuItems,AccessibleContext 采用 AccessibleJCheckBoxMenuItem 的形式。如有必要,可创建一个新的 AccessibleJCheckBoxMenuItem 实例。

指定者:
接口 Accessible 中的 getAccessibleContext
覆盖:
JMenuItem 中的 getAccessibleContext
返回:
一个 AccessibleJCheckBoxMenuItem,它充当此 AccessibleJCheckBoxMenuItem 的 AccessibleContext

JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策