Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: CheckboxMenuItem [javadoc | source]
java.lang.Object
   java.awt.MenuComponent
      java.awt.MenuItem
         java.awt.CheckboxMenuItem

All Implemented Interfaces:
    ItemSelectable, Accessible, Serializable

Direct Known Subclasses:
   

This class represents a check box that can be included in a menu. Selecting the check box in the menu changes its state from "on" to "off" or from "off" to "on."

The following picture depicts a menu which contains an instance of CheckBoxMenuItem:

Menu labeled Examples, containing items Basic, Simple, Check, and More Examples. The Check item is a CheckBoxMenuItem instance, in the off state.

The item labeled Check shows a check box menu item in its "off" state.

When a check box menu item is selected, AWT sends an item event to the item. Since the event is an instance of ItemEvent, the processEvent method examines the event and passes it along to processItemEvent. The latter method redirects the event to any ItemListener objects that have registered an interest in item events generated by this menu item.

Nested Class Summary:
protected class  CheckboxMenuItem.AccessibleAWTCheckboxMenuItem  Inner class of CheckboxMenuItem used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

This class implements accessibility support for the CheckboxMenuItem class. It provides an implementation of the Java Accessibility API appropriate to checkbox menu item user-interface elements. 

Field Summary
 boolean state    The state of a checkbox menu item 
transient  ItemListener itemListener     
Fields inherited from java.awt.MenuItem:
enabled,  label,  actionCommand,  eventMask,  actionListener
Fields inherited from java.awt.MenuComponent:
peer,  parent,  appContext,  font,  newEventsOnly,  actionListenerK,  itemListenerK,  accessibleContext
Constructor:
 public CheckboxMenuItem() throws HeadlessException 
    Create a check box menu item with an empty label. The item's state is initially set to "off."
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true
    since: JDK1.1 -
 public CheckboxMenuItem(String label) throws HeadlessException 
    Create a check box menu item with the specified label. The item's state is initially set to "off."
    Parameters:
    label - a string label for the check box menu item, or null for an unlabeled menu item.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true
 public CheckboxMenuItem(String label,
    boolean state) throws HeadlessException 
    Create a check box menu item with the specified label and state.
    Parameters:
    label - a string label for the check box menu item, or null for an unlabeled menu item.
    state - the initial state of the menu item, where true indicates "on" and false indicates "off."
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true
    since: JDK1.1 -
Method from java.awt.CheckboxMenuItem Summary:
addItemListener,   addNotify,   constructComponentName,   doMenuEvent,   eventEnabled,   getAccessibleContext,   getItemListeners,   getListeners,   getSelectedObjects,   getState,   paramString,   processEvent,   processItemEvent,   removeItemListener,   setState
Methods from java.awt.MenuItem:
addActionListener,   addNotify,   constructComponentName,   deleteShortcut,   deleteShortcut,   disable,   disableEvents,   doMenuEvent,   enable,   enable,   enableEvents,   eventEnabled,   getAccessibleContext,   getActionCommand,   getActionCommandImpl,   getActionListeners,   getLabel,   getListeners,   getShortcut,   getShortcutMenuItem,   handleShortcut,   isEnabled,   paramString,   processActionEvent,   processEvent,   removeActionListener,   setActionCommand,   setEnabled,   setLabel,   setShortcut
Methods from java.awt.MenuComponent:
constructComponentName,   dispatchEvent,   dispatchEventImpl,   eventEnabled,   getAccessControlContext,   getAccessibleChildIndex,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getFont,   getFont_NoClientCode,   getName,   getParent,   getParent_NoClientCode,   getPeer,   getTreeLock,   paramString,   postEvent,   processEvent,   removeNotify,   setFont,   setName,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.CheckboxMenuItem Detail:
 public synchronized  void addItemListener(ItemListener l) 
    Adds the specified item listener to receive item events from this check box menu item. Item events are sent in response to user actions, but not in response to calls to setState(). If l is null, no exception is thrown and no action is performed.

    Refer to AWT Threading Issues for details on AWT's threading model.

 public  void addNotify() 
    Creates the peer of the checkbox item. This peer allows us to change the look of the checkbox item without changing its functionality. Most applications do not call this method directly.
 String constructComponentName() 
    Construct a name for this MenuComponent. Called by getName() when the name is null.
  void doMenuEvent(long when,
    int modifiers) 
 boolean eventEnabled(AWTEvent e) 
 public AccessibleContext getAccessibleContext() 
    Gets the AccessibleContext associated with this CheckboxMenuItem. For checkbox menu items, the AccessibleContext takes the form of an AccessibleAWTCheckboxMenuItem. A new AccessibleAWTCheckboxMenuItem is created if necessary.
 public synchronized ItemListener[] getItemListeners() 
    Returns an array of all the item listeners registered on this checkbox menuitem.
 public T[] getListeners(Class<T> listenerType) 
    Returns an array of all the objects currently registered as FooListeners upon this CheckboxMenuItem. FooListeners are registered using the addFooListener method.

    You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a CheckboxMenuItem c for its item listeners with the following code:

    ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));
    If no such listeners exist, this method returns an empty array.
 public synchronized Object[] getSelectedObjects() 
    Returns the an array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.
 public boolean getState() 
    Determines whether the state of this check box menu item is "on" or "off."
 public String paramString() 
    Returns a string representing the state of this CheckBoxMenuItem. 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.
 protected  void processEvent(AWTEvent e) 
    Processes events on this check box menu item. If the event is an instance of ItemEvent, this method invokes the processItemEvent method. If the event is not an item event, it invokes processEvent on the superclass.

    Check box menu items currently support only item events.

    Note that if the event parameter is null the behavior is unspecified and may result in an exception.

 protected  void processItemEvent(ItemEvent e) 
    Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects.

    This method is not called unless item events are enabled for this menu item. Item events are enabled when one of the following occurs:

    • An ItemListener object is registered via addItemListener.
    • Item events are enabled via enableEvents.

    Note that if the event parameter is null the behavior is unspecified and may result in an exception.

 public synchronized  void removeItemListener(ItemListener l) 
    Removes the specified item listener so that it no longer receives item events from this check box menu item. If l is null, no exception is thrown and no action is performed.

    Refer to AWT Threading Issues for details on AWT's threading model.

 public synchronized  void setState(boolean b) 
    Sets this check box menu item to the specifed state. The boolean value true indicates "on" while false indicates "off."

    Note that this method should be primarily used to initialize the state of the check box menu item. Programmatically setting the state of the check box menu item will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.