JCheckBoxMenuItempublic class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, AccessibleA menu item that can be selected or deselected. If selected, the menu
item typically appears with a checkmark next to it. If unselected or
deselected, the menu item appears without a checkmark. Like a regular
menu item, a check box menu item can have either text or a graphic
icon associated with it, or both.
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.
For further information and examples of using check box menu items,
see How to Use Menus,
a section in The Java Tutorial.
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 JavaBeansTM
has been added to the java.beans package.
Please see {@link java.beans.XMLEncoder}. |
Fields Summary |
---|
private static final String | uiClassID |
Constructors Summary |
---|
public JCheckBoxMenuItem()Creates an initially unselected check box menu item with no set text or icon.
this(null, null, false);
| public JCheckBoxMenuItem(Icon icon)Creates an initially unselected check box menu item with an icon.
this(null, icon, false);
| public JCheckBoxMenuItem(String text)Creates an initially unselected check box menu item with text.
this(text, null, false);
| public JCheckBoxMenuItem(Action a)Creates a menu item whose properties are taken from the
Action supplied.
this();
setAction(a);
| public JCheckBoxMenuItem(String text, Icon icon)Creates an initially unselected check box menu item with the specified text and icon.
this(text, icon, false);
| public JCheckBoxMenuItem(String text, boolean b)Creates a check box menu item with the specified text and selection state.
this(text, null, b);
| public JCheckBoxMenuItem(String text, Icon icon, boolean b)Creates a check box menu item with the specified text, icon, and selection state.
super(text, icon);
setModel(new JToggleButton.ToggleButtonModel());
setSelected(b);
setFocusable(false);
|
Methods Summary |
---|
public javax.accessibility.AccessibleContext | getAccessibleContext()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.
if (accessibleContext == null) {
accessibleContext = new AccessibleJCheckBoxMenuItem();
}
return accessibleContext;
| public java.lang.Object[] | getSelectedObjects()Returns an array (length 1) containing the check box menu item
label or null if the check box is not selected.
if (isSelected() == false)
return null;
Object[] selectedObjects = new Object[1];
selectedObjects[0] = getText();
return selectedObjects;
| public boolean | getState()Returns the selected-state of the item. This method
exists for AWT compatibility only. New code should
use isSelected() instead.
return isSelected();
| public java.lang.String | getUIClassID()Returns the name of the L&F class
that renders this component.
return uiClassID;
| protected java.lang.String | paramString()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 null .
return super.paramString();
| 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.
setSelected(b);
| private void | writeObject(java.io.ObjectOutputStream s)See readObject() and writeObject() in JComponent for more
information about serialization in Swing.
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|
|