- 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
@JavaBean(description="A menu item which can be selected or deselected.")public class JCheckBoxMenuItemextends JMenuItemimplements SwingConstants, Accessible
可以选择或取消选择的菜单项。 如果选中,菜单项通常会显示旁边的复选标记。 如果未选中或取消选择,则菜单项不会显示复选标记。 与常规菜单项一样,复选框菜单项可以包含与之关联的文本或图形图标,或两者都有。无论是
isSelected
/setSelected
或getState
/setState
可以用来确定/指定菜单项的选择状态。 首选方法是isSelected
和setSelected
,它们适用于所有菜单和按钮。 存在getState
和setState
方法以与其他组件集兼容。可以通过
Action
配置菜单项,并在某种程度上控制。 将Action
与菜单项一起使用除了直接配置菜单项外,还有许多其他好处。 有关更多详细信息,请参阅Swing Components SupportingAction
,您可以在“Java教程”中的How to Use Actions部分中找到更多信息。有时需要从菜单中选择几个复选框菜单项。 在这种情况下,单击一个复选框菜单项并不关闭菜单是很有用的。 这种行为可以由客户端
JComponent.putClientProperty(java.lang.Object, java.lang.Object)
或名为"CheckBoxMenuItem.doNotCloseOnMouseClick"
的外观和感觉UIManager.put(java.lang.Object, java.lang.Object)
字段"CheckBoxMenuItem.doNotCloseOnMouseClick"
。 默认值为false
。 将属性设置为true
可防止菜单在鼠标单击时关闭。 如果设置了client属性,则始终使用其值; 否则查询L&F财产。 注意:某些L&F
可能会忽略此属性。 所有内置的L&F
都继承了这种行为。有关使用复选框菜单项的更多信息和示例,请参阅“Java教程”中的 How to Use Menus部分。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans
软件包中添加了对所有JavaBeansjava.beans
长期存储的支持。 请参阅XMLEncoder
。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 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
-
-
字段汇总
-
声明的属性在类 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
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
声明的属性在类 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
-
Fields declared in interface 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
-
-
构造方法摘要
构造方法 构造器 描述 JCheckBoxMenuItem()
创建一个最初未选中的复选框菜单项,没有设置文本或图标。JCheckBoxMenuItem(String text)
使用文本创建最初未选中的复选框菜单项。JCheckBoxMenuItem(String text, boolean b)
创建具有指定文本和选择状态的复选框菜单项。JCheckBoxMenuItem(String text, Icon icon)
使用指定的文本和图标创建最初未选中的复选框菜单项。JCheckBoxMenuItem(String text, Icon icon, boolean b)
创建具有指定文本,图标和选择状态的复选框菜单项。JCheckBoxMenuItem(Action a)
创建一个菜单项,其属性取自提供的Action。JCheckBoxMenuItem(Icon icon)
创建一个带有图标的最初未选中的复选框菜单项。
-
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 AccessibleContext
getAccessibleContext()
获取与此JCheckBoxMenuItem关联的AccessibleContext。Object[]
getSelectedObjects()
返回包含复选框菜单项标签的数组(长度为1),如果未选中该复选框,则返回null。boolean
getState()
返回项的选定状态。String
getUIClassID()
返回呈现此组件的L&F类的名称。protected String
paramString()
返回此JCheckBoxMenuItem的字符串表示形式。void
setState(boolean b)
设置项目的选定状态。-
声明方法的类 javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, 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, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, 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, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, 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, 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, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, 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, 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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
构造方法详细信息
-
JCheckBoxMenuItem
public JCheckBoxMenuItem()
创建一个最初未选中的复选框菜单项,没有设置文本或图标。
-
JCheckBoxMenuItem
public JCheckBoxMenuItem(Icon icon)
创建一个带有图标的最初未选中的复选框菜单项。- 参数
-
icon
-的图标JCheckBoxMenuItem
。
-
JCheckBoxMenuItem
public JCheckBoxMenuItem(String text)
使用文本创建最初未选中的复选框菜单项。- 参数
-
text
-该文JCheckBoxMenuItem
-
JCheckBoxMenuItem
public JCheckBoxMenuItem(Action a)
创建一个菜单项,其属性取自提供的Action。- 参数
-
a
-的的作用JCheckBoxMenuItem
- 从以下版本开始:
- 1.3
-
JCheckBoxMenuItem
public JCheckBoxMenuItem(String text, Icon icon)
使用指定的文本和图标创建最初未选中的复选框菜单项。- 参数
-
text
-该文JCheckBoxMenuItem
-
icon
-的图标JCheckBoxMenuItem
-
JCheckBoxMenuItem
public JCheckBoxMenuItem(String text, boolean b)
创建具有指定文本和选择状态的复选框菜单项。- 参数
-
text
- 复选框菜单项的文本。 -
b
- 复选框菜单项的选定状态
-
-
方法详细信息
-
getUIClassID
@BeanProperty(bound=false)public String getUIClassID()
返回呈现此组件的L&F类的名称。- 重写:
-
getUIClassID
类JMenuItem
- 结果
- “CheckBoxMenuItemUI”
- 另请参见:
-
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
getState
public boolean getState()
返回项的选定状态。 此方法仅适用于AWT兼容性。 新代码应该使用isSelected()代替。- 结果
- 如果选中该项,则为true
-
setState
@BeanProperty(bound=false, hidden=true, description="The selection state of the check box menu item")public void setState(boolean b)
设置项目的选定状态。 此方法仅适用于AWT兼容性。 新代码应该使用setSelected()。- 参数
-
b
- 一个布尔值,表示项目的selected-state,其中true = selected
-
getSelectedObjects
@BeanProperty(bound=false)public Object[] getSelectedObjects()
返回包含复选框菜单项标签的数组(长度为1),如果未选中该复选框,则返回null。- Specified by:
-
getSelectedObjects
在接口ItemSelectable
- 重写:
-
getSelectedObjects
类AbstractButton
- 结果
- 包含一个Object的数组 - 菜单项的文本 - 如果选择了该项; 否则为null
-
paramString
protected String paramString()
返回此JCheckBoxMenuItem的字符串表示形式。 此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null
。- 重写:
-
paramString
类JMenuItem
- 结果
- 此JCheckBoxMenuItem的字符串表示形式。
-
getAccessibleContext
@BeanProperty(bound=false)public AccessibleContext getAccessibleContext()
获取与此JCheckBoxMenuItem关联的AccessibleContext。 对于JCheckBoxMenuItems,AccessibleContext采用AccessibleJCheckBoxMenuItem的形式。 如有必要,将创建一个新的AccessibleJCheckBoxMenuItem实例。- Specified by:
-
getAccessibleContext
在接口Accessible
- 重写:
-
getAccessibleContext
在类JMenuItem
- 结果
- an AccessibleJCheckBoxMenuItem that serves as the AccessibleContext of this AccessibleJCheckBoxMenuItem
-
-