javax.swing

Class JCheckBoxMenuItem

public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, Accessible

A menu item that displays a checkbox. Its behaviour is very similar to {@link JCheckBox}. Just like the JCheckBox, user can check and uncheck this menu item by clicking on it. Also {@link AbstractButton#setSelected} and {@link #setState} can be use used for the same purpose. JCheckBoxMenuItem uses ToggleButtonModel to keep track of its selection.
Nested Class Summary
protected classJCheckBoxMenuItem.AccessibleJCheckBoxMenuItem
Provides the accessibility features for the JCheckBoxMenuItem component.
Constructor Summary
JCheckBoxMenuItem()
Creates a new JCheckBoxMenuItem object.
JCheckBoxMenuItem(Icon icon)
Creates a new JCheckBoxMenuItem with given icon
JCheckBoxMenuItem(String text)
Creates a new JCheckBoxMenuItem with given label
JCheckBoxMenuItem(Action action)
Creates a new JCheckBoxMenuItem using given action
JCheckBoxMenuItem(String text, Icon icon)
Creates a new JCheckBoxMenuItem object with given label and icon
JCheckBoxMenuItem(String text, boolean state)
Creates a new JCheckBoxMenuItem object using specified label and marked as checked if given 'state' is true.
JCheckBoxMenuItem(String text, Icon icon, boolean state)
Creates a new JCheckBoxMenuItem object with given label, icon, and marked as checked if given 'state' is true.
Method Summary
AccessibleContextgetAccessibleContext()
Returns the object that provides accessibility features for this JCheckBoxMenuItem component.
Object[]getSelectedObjects()
This method returns array containing label of this menu item if it is selected and null otherwise.
booleangetState()
Returns checked state for this check box menu item.
StringgetUIClassID()
This method returns a name to identify which look and feel class will be the UI delegate for the menuItem.
protected StringparamString()
Returns a string describing the attributes for the JCheckBoxMenuItem component, for use in debugging.
voidrequestFocus()
This method overrides JComponent.requestFocus with an empty implementation, since JCheckBoxMenuItems should not receive focus in general.
voidsetState(boolean state)
Sets state for this check box menu item.

Constructor Detail

JCheckBoxMenuItem

public JCheckBoxMenuItem()
Creates a new JCheckBoxMenuItem object.

JCheckBoxMenuItem

public JCheckBoxMenuItem(Icon icon)
Creates a new JCheckBoxMenuItem with given icon

Parameters: icon Icon for this menu item

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text)
Creates a new JCheckBoxMenuItem with given label

Parameters: text Label for this menu item

JCheckBoxMenuItem

public JCheckBoxMenuItem(Action action)
Creates a new JCheckBoxMenuItem using given action

Parameters: action Action for this menu item.

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text, Icon icon)
Creates a new JCheckBoxMenuItem object with given label and icon

Parameters: text Label for this menu item icon Icon for this menu item

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text, boolean state)
Creates a new JCheckBoxMenuItem object using specified label and marked as checked if given 'state' is true.

Parameters: text Label for this menu item state true if this item should be in checked state and false otherwise

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text, Icon icon, boolean state)
Creates a new JCheckBoxMenuItem object with given label, icon, and marked as checked if given 'state' is true.

Parameters: text Label for this menu item icon icon for this menu item state true if this item should be in checked state and false otherwise

Method Detail

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JCheckBoxMenuItem component.

Returns: The accessible context (an instance of {@link AccessibleJCheckBoxMenuItem}).

getSelectedObjects

public Object[] getSelectedObjects()
This method returns array containing label of this menu item if it is selected and null otherwise.

Returns: Array containing label of this menu item if this menu item is selected or null otherwise.

getState

public boolean getState()
Returns checked state for this check box menu item.

Returns: Returns true if this menu item is in checked state and false otherwise.

getUIClassID

public String getUIClassID()
This method returns a name to identify which look and feel class will be the UI delegate for the menuItem.

Returns: The Look and Feel classID. "JCheckBoxMenuItemUI"

paramString

protected String paramString()
Returns a string describing the attributes for the JCheckBoxMenuItem component, for use in debugging. The return value is guaranteed to be non-null, but the format of the string may vary between implementations.

Returns: A string describing the attributes of the JCheckBoxMenuItem.

requestFocus

public void requestFocus()
This method overrides JComponent.requestFocus with an empty implementation, since JCheckBoxMenuItems should not receive focus in general.

setState

public void setState(boolean state)
Sets state for this check box menu item. If given 'state' is true, then mark menu item as checked, and uncheck this menu item otherwise.

Parameters: state new state for this menu item