java.awt

Class CheckboxMenuItem

  • All Implemented Interfaces:
    ItemSelectable, Serializable, Accessible

    public class CheckboxMenuItem
    extends MenuItem
    implements ItemSelectable, Accessible
    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.

    Since:
    JDK1.0
    See Also:
    ItemEvent, ItemListener, Serialized Form
    • Constructor Detail

      • CheckboxMenuItem

        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
        See Also:
        GraphicsEnvironment.isHeadless()
      • CheckboxMenuItem

        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
        Since:
        JDK1.1
        See Also:
        GraphicsEnvironment.isHeadless()
    • Method Detail

      • getState

        public boolean getState()
        Determines whether the state of this check box menu item is "on" or "off."
        Returns:
        the state of this check box menu item, where true indicates "on" and false indicates "off"
        See Also:
        setState(boolean)
      • setState

        public 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.

        Parameters:
        b - true if the check box menu item is on, otherwise false
        See Also:
        getState()
      • getListeners

        public <T extends EventListener> 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.
        Overrides:
        getListeners in class MenuItem
        Parameters:
        listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
        Returns:
        an array of all objects registered as FooListeners on this checkbox menuitem, or an empty array if no such listeners have been added
        Throws:
        ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
        Since:
        1.3
        See Also:
        getItemListeners()
      • processEvent

        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.

        Overrides:
        processEvent in class MenuItem
        Parameters:
        e - the event
        Since:
        JDK1.1
        See Also:
        ItemEvent, processItemEvent(java.awt.event.ItemEvent)
      • processItemEvent

        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.

        Parameters:
        e - the item event
        Since:
        JDK1.1
        See Also:
        ItemEvent, ItemListener, addItemListener(java.awt.event.ItemListener), MenuItem.enableEvents(long)
      • paramString

        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.
        Overrides:
        paramString in class MenuItem
        Returns:
        the parameter string of this check box menu item
      • getAccessibleContext

        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.
        Specified by:
        getAccessibleContext in interface Accessible
        Overrides:
        getAccessibleContext in class MenuItem
        Returns:
        an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem
        Since:
        1.3

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

24/11/2024 23:21:01 Cette version de la page est en cache (à la date du 24/11/2024 23:21:01) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.

Document créé le 29/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/awt/CheckboxMenuItem.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, CheckboxMenuItem

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut