Java Reference
In-Depth Information
public JCheckBoxMenuItem(Icon icon)
Icon boyIcon = new ImageIcon("boy-r.jpg");
JCheckBoxMenuItem jCheckBoxMenuItem = new JCheckBoxMenuItem(boyIcon);
public JCheckBoxMenuItem(String text, Icon icon)
JCheckBoxMenuItem jCheckBoxMenuItem = new JCheckBoxMenuItem("Boy", boyIcon);
public JCheckBoxMenuItem(String text, boolean state)
JCheckBoxMenuItem jCheckBoxMenuItem = new JCheckBoxMenuItem("Girl", true);
public JCheckBoxMenuItem(String text, Icon icon, boolean state)
Icon girlIcon = new ImageIcon("girl-r.jpg");
JCheckBoxMenuItem jCheckBoxMenuItem = new JCheckBoxMenuItem("Girl", girlIcon, true);
public JCheckBoxMenuItem(Action action)
Action action = ...;
JCheckBoxMenuItem jCheckBoxMenuItem = new JCheckBoxMenuItem(action);
Unlike the
JCheckBox
, the icon is part of the label and not a separate device to indicate
whether something is checked. If either the text label or the icon isn't passed to the constructor,
that part of the item label will be set to its default value of empty. By default, a
JCheckBoxMenuItem
is
unselected.
■
Note
Creating a
JCheckBoxMenuItem
with an icon has no effect on the appearance of the check box
next to the menu item. It's strictly part of the label for the
JCheckBoxMenuItem
.
JCheckBoxMenuItem Properties
Most of the
JCheckBoxMenuItem
properties are inherited from the many superclasses of
JCheckBoxMenuItem
. Table 6-11 lists the four properties defined by
JCheckBoxMenuItem
.
Table 6-11.
JCheckBoxMenuItem Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
selectedObjects
Object
[ ]
Read-only
state
boolean
Read-write
UIClassID
String
Read-only