- 所有已实现的接口:
-
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,MenuElement
,SwingConstants
可以使用isSelected
/setSelected
或getState
/setState
来确定/指定菜单项的选择状态。首选方法是isSelected
和setSelected
,适用于所有菜单和按钮。getState
和setState
方法存在是为了与其他组件集兼容。
菜单项可以通过Action
进行配置和在一定程度上控制。使用Action
与菜单项有许多好处,超出了直接配置菜单项。有关更多详细信息,请参阅支持Action
的Swing组件,您可以在The Java Tutorial的如何使用Actions部分找到更多信息。
有时需要从菜单中选择几个复选框菜单项。在这种情况下,有用的是单击一个复选框菜单项不会关闭菜单。这种行为可以通过客户端JComponent.putClientProperty(java.lang.Object, java.lang.Object)
或外观和感觉UIManager.put(java.lang.Object, java.lang.Object)
属性"CheckBoxMenuItem.doNotCloseOnMouseClick"
来控制。默认值为false
。将属性设置为true
会防止鼠标单击时关闭菜单。如果设置了客户端属性,则始终使用其值;否则查询L&F属性。注意:一些L&F
可能会忽略此属性。所有内置L&F
都继承此行为。
有关更多关于使用复选框菜单项的信息和示例,请参阅The Java Tutorial中的如何使用菜单部分。
警告:Swing不是线程安全的。更多信息请参阅Swing的线程策略。
警告:此类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans
包中。请参阅XMLEncoder
。
- 自:
- 1.2
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
此类实现了JCheckBoxMenuItem
类的辅助功能支持。Nested classes/interfaces declared in class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItem
Nested classes/interfaces declared in class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
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.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
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
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
-
Constructor Summary
ConstructorDescription创建一个最初未选中的复选框菜单项,没有设置文本或图标。JCheckBoxMenuItem
(String text) 创建一个带有文本的最初未选中的复选框菜单项。JCheckBoxMenuItem
(String text, boolean b) 创建具有指定文本和选择状态的复选框菜单项。JCheckBoxMenuItem
(String text, Icon icon) 创建一个带有指定文本和图标的最初未选中的复选框菜单项。JCheckBoxMenuItem
(String text, Icon icon, boolean b) 创建具有指定文本、图标和选择状态的复选框菜单项。创建一个属性取自提供的Action的菜单项。JCheckBoxMenuItem
(Icon icon) 创建一个带有图标的最初未选中的复选框菜单项。 -
Method Summary
Methods declared in class 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, setModel, setUI, updateUI
Methods declared in class 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, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
Methods declared in class 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, hide, 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
Methods declared in class 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
Methods declared in class 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, 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
-
Constructor Details
-
JCheckBoxMenuItem
public JCheckBoxMenuItem()创建一个最初未选中的复选框菜单项,没有设置文本或图标。 -
JCheckBoxMenuItem
创建一个带有图标的最初未选中的复选框菜单项。- 参数:
-
icon
-JCheckBoxMenuItem
的图标。
-
JCheckBoxMenuItem
创建一个带有文本的最初未选中的复选框菜单项。- 参数:
-
text
-JCheckBoxMenuItem
的文本
-
JCheckBoxMenuItem
创建一个属性取自提供的Action的菜单项。- 参数:
-
a
-JCheckBoxMenuItem
的动作 - 自:
- 1.3
-
JCheckBoxMenuItem
创建一个带有指定文本和图标的最初未选中的复选框菜单项。- 参数:
-
text
-JCheckBoxMenuItem
的文本 -
icon
-JCheckBoxMenuItem
的图标
-
JCheckBoxMenuItem
创建具有指定文本和选择状态的复选框菜单项。- 参数:
-
text
- 复选框菜单项的文本。 -
b
- 复选框菜单项的选择状态
-
JCheckBoxMenuItem
创建具有指定文本、图标和选择状态的复选框菜单项。- 参数:
-
text
- 复选框菜单项的文本 -
icon
- 复选框菜单项的图标 -
b
- 复选框菜单项的选择状态
-
-
Method Details
-
getUIClassID
返回呈现此组件的L&F类的名称。- 覆盖:
-
getUIClassID
在类JMenuItem
中 - 返回:
- 字符串"CheckBoxMenuItemUI"
- 参见:
-
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
- 一个布尔值,指示该项的选择状态,其中true=已选中
-
getSelectedObjects
返回一个包含复选框菜单项标签的数组(长度为1),如果复选框未被选中则返回null。- 指定者:
-
getSelectedObjects
在接口ItemSelectable
中 - 覆盖:
-
getSelectedObjects
在类AbstractButton
中 - 返回:
- 一个包含一个对象的数组 -- 如果该项被选中,则为菜单项的文本;否则为null
-
paramString
返回此JCheckBoxMenuItem的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null
。- 覆盖:
-
paramString
在类JMenuItem
中 - 返回:
- 此JCheckBoxMenuItem的字符串表示形式。
-
getAccessibleContext
获取与此JCheckBoxMenuItem关联的AccessibleContext。对于JCheckBoxMenuItems,AccessibleContext采用AccessibleJCheckBoxMenuItem的形式。如果需要,将创建一个新的AccessibleJCheckBoxMenuItem实例。- 指定者:
-
getAccessibleContext
在接口Accessible
中 - 覆盖:
-
getAccessibleContext
在类JMenuItem
中 - 返回:
- 作为此AccessibleJCheckBoxMenuItem的AccessibleContext的AccessibleJCheckBoxMenuItem
-