Either isSelected/setSelected or
getState/setState can be used
to determine/specify the menu item's selection state. The
preferred methods are isSelected and
setSelected, which work for all menus and buttons.
The getState and setState methods exist for
compatibility with other component sets.
Menu items can be configured, and to some degree controlled, by
Actions. Using an
Action with a menu item has many benefits beyond directly
configuring a menu item. Refer to
Swing Components Supporting Action for more
details, and you can find more information in How
to Use Actions, a section in The Java Tutorial.
Some times it is required to select several check box menu items from a menu.
In this case it is useful that clicking on one check box menu item does not
close the menu. Such behavior can be controlled either by client
JComponent#putClientProperty or the Look and Feel
UIManager#put property named
"CheckBoxMenuItem.doNotCloseOnMouseClick". The default value is
false. Setting the property to true prevents the menu from
closing when it is clicked by the mouse. If the client property is set its
value is always used; otherwise the L&F property is queried.
Note
some L&Fs may ignore this property. All built-in L&Fs
inherit this behaviour.
For further information and examples of using check box menu items, see How to Use Menus, a section in The Java Tutorial.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | JCheckBoxMenuItem.
This class implements accessibility support for the
|
| Modifier and Type | Field and Description |
|---|---|
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JCheckBoxMenuItem(Icon
the icon of the icon)JCheckBoxMenuItem.Creates an initially unselected check box menu item with an icon. |
| public | JCheckBoxMenuItem(String
the text of the text)JCheckBoxMenuItemCreates an initially unselected check box menu item with text. |
| public | JCheckBoxMenuItem(Action
the action of the a)JCheckBoxMenuItemCreates a menu item whose properties are taken from the Action supplied. |
| public | JCheckBoxMenuItem(String
the text of the text, Icon JCheckBoxMenuItemthe icon of the icon)JCheckBoxMenuItemCreates an initially unselected check box menu item with the specified text and icon. |
| public | JCheckBoxMenuItem(String
the text of the check box menu item. text, boolean the selected state of the check box menu item b)Creates a check box menu item with the specified text and selection state. |
| public | JCheckBoxMenuItem(String
the text of the check box menu item text, Icon the icon of the check box menu item icon, boolean the selected state of the check box menu item b)Creates a check box menu item with the specified text, icon, and selection state. |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleContext | Returns: an AccessibleJCheckBoxMenuItem that serves as the AccessibleContext of this AccessibleJCheckBoxMenuItemOverrides javax. Implements javax. Gets the AccessibleContext associated with this JCheckBoxMenuItem. |
| public Object[] | Returns: an array containing one Object -- the text of the menu item -- if the item is selected; otherwise nullOverrides javax. Implements java. Returns an array (length 1) containing the check box menu item label or null if the check box is not selected. |
| public boolean | |
| public String | Returns: the string "CheckBoxMenuItemUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| protected String | Returns: a string representation of this JCheckBoxMenuItem.Overrides javax. Returns a string representation of this JCheckBoxMenuItem. |
| public synchronized void | setState(boolean
a boolean value indicating the item's
selected-state, where true=selected b)Sets the selected-state of the item. |
| pack-priv boolean | shouldUpdateSelectedStateFromAction()
Overrides javax. Overridden to return true, JCheckBoxMenuItem supports the selected state. |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing. |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem() Creates an initially unselected check box menu item with no set text or icon. | |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(Icon icon) Creates an initially unselected check box menu item with an icon.
| |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(String text) Creates an initially unselected check box menu item with text.
| |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(Action a) Creates a menu item whose properties are taken from the Action supplied.
| |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(String text, Icon icon) Creates an initially unselected check box menu item with the specified text and icon. | |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(String text, boolean b) Creates a check box menu item with the specified text and selection state.
| |
| JCheckBoxMenuItem | back to summary |
|---|---|
| public JCheckBoxMenuItem(String text, Icon icon, boolean b) Creates a check box menu item with the specified text, icon, and selection state. | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides javax. Implements javax. Gets the AccessibleContext associated with this JCheckBoxMenuItem. For JCheckBoxMenuItems, the AccessibleContext takes the form of an AccessibleJCheckBoxMenuItem. A new AccessibleJCheckBoxMenuItem instance is created if necessary.
| |
| getSelectedObjects | back to summary |
|---|---|
| public Object[] getSelectedObjects() Overrides javax. Implements java. Returns an array (length 1) containing the check box menu item label or null if the check box is not selected.
| |
| getState | back to summary |
|---|---|
| public boolean getState() Returns the selected-state of the item. This method exists for AWT compatibility only. New code should use isSelected() instead.
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this JCheckBoxMenuItem. This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be
| |
| setState | back to summary |
|---|---|
| public synchronized void setState(boolean b) Sets the selected-state of the item. This method exists for AWT compatibility only. New code should use setSelected() instead.
| |
| shouldUpdateSelectedStateFromAction | back to summary |
|---|---|
| pack-priv boolean shouldUpdateSelectedStateFromAction() Overrides javax. Overridden to return true, JCheckBoxMenuItem supports the selected state. | |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing.
| |
JCheckBoxMenuItem class. It provides an implementation
of the Java Accessibility API appropriate to checkbox menu item
user-interface elements.Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. Get the role of this object. |
| AccessibleJCheckBoxMenuItem | back to summary |
|---|---|
| protected AccessibleJCheckBoxMenuItem() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
| |