java.lang.Objectjava.awt.MenuComponent
java.awt.MenuItem
java.awt.CheckboxMenuItem
public class CheckboxMenuItem
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:
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.
ItemEvent,
ItemListener,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
CheckboxMenuItem.AccessibleAWTCheckboxMenuItem
Inner class of CheckboxMenuItem used to provide default support for accessibility. |
| Nested classes/interfaces inherited from class java.awt.MenuItem |
|---|
MenuItem.AccessibleAWTMenuItem |
| Nested classes/interfaces inherited from class java.awt.MenuComponent |
|---|
MenuComponent.AccessibleAWTMenuComponent |
| Constructor Summary | |
|---|---|
CheckboxMenuItem()
Create a check box menu item with an empty label. |
|
CheckboxMenuItem(String label)
Create a check box menu item with the specified label. |
|
CheckboxMenuItem(String label,
boolean state)
Create a check box menu item with the specified label and state. |
|
| Method Summary | ||
|---|---|---|
void |
addItemListener(ItemListener l)
Adds the specified item listener to receive item events from this check box menu item. |
|
void |
addNotify()
Creates the peer of the checkbox item. |
|
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this CheckboxMenuItem. |
|
ItemListener[] |
getItemListeners()
Returns an array of all the item listeners registered on this checkbox menuitem. |
|
|
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners
upon this CheckboxMenuItem. |
|
Object[] |
getSelectedObjects()
Returns the an array (length 1) containing the checkbox menu item label or null if the checkbox is not selected. |
|
boolean |
getState()
Determines whether the state of this check box menu item is "on" or "off." |
|
String |
paramString()
Returns a string representing the state of this CheckBoxMenuItem. |
|
protected void |
processEvent(AWTEvent e)
Processes events on this check box menu item. |
|
protected void |
processItemEvent(ItemEvent e)
Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects. |
|
void |
removeItemListener(ItemListener l)
Removes the specified item listener so that it no longer receives item events from this check box menu item. |
|
void |
setState(boolean b)
Sets this check box menu item to the specifed state. |
|
| Methods inherited from class java.awt.MenuItem |
|---|
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getShortcut, isEnabled, processActionEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut |
| Methods inherited from class java.awt.MenuComponent |
|---|
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, postEvent, removeNotify, setFont, setName, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CheckboxMenuItem()
throws HeadlessException
HeadlessException - if GraphicsEnvironment.isHeadless()
returns trueGraphicsEnvironment.isHeadless()public CheckboxMenuItem(String label) throws HeadlessException
label - a string label for the check box menu item,
or null for an unlabeled menu item.
HeadlessException - if GraphicsEnvironment.isHeadless()
returns trueGraphicsEnvironment.isHeadless()public CheckboxMenuItem(String label, boolean state) throws HeadlessException
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."
HeadlessException - if GraphicsEnvironment.isHeadless()
returns trueGraphicsEnvironment.isHeadless()| Method Detail |
|---|
public void addNotify()
public boolean getState()
true indicates "on" and
false indicates "off"setState(boolean)public void setState(boolean b)
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.
b - true if the check box
menu item is on, otherwise falsegetState()public Object[] getSelectedObjects()
getSelectedObjects in interface ItemSelectableItemSelectablepublic void addItemListener(ItemListener l)
addItemListener in interface ItemSelectablel - the item listenerremoveItemListener(java.awt.event.ItemListener),
getItemListeners(),
setState(boolean),
ItemEvent,
ItemListenerpublic void removeItemListener(ItemListener l)
removeItemListener in interface ItemSelectablel - the item listeneraddItemListener(java.awt.event.ItemListener),
getItemListeners(),
ItemEvent,
ItemListenerpublic ItemListener[] getItemListeners()
ItemListeners
or an empty array if no item
listeners are currently registeredaddItemListener(java.awt.event.ItemListener),
removeItemListener(java.awt.event.ItemListener),
ItemEvent,
ItemListenerpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
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:
getListeners in class MenuItemlistenerType - the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListeners on this checkbox menuitem,
or an empty array if no such
listeners have been added
ClassCastException - if listenerType
doesn't specify a class or interface that implements
java.util.EventListenergetItemListeners()protected void processEvent(AWTEvent e)
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.
processEvent in class MenuIteme - the eventItemEvent,
processItemEvent(java.awt.event.ItemEvent)protected void processItemEvent(ItemEvent e)
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:
ItemListener object is registered
via addItemListener.
enableEvents.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e - the item eventItemEvent,
ItemListener,
addItemListener(java.awt.event.ItemListener),
MenuItem.enableEvents(long)public String paramString()
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.
paramString in class MenuItempublic AccessibleContext getAccessibleContext()
getAccessibleContext in interface AccessiblegetAccessibleContext in class MenuItemCes informations proviennent du site de http://java.sun.com
Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :
Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.
Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.
Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.
Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.
Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
6 mots clés dont 0 définis manuellement (plus d'information...).
Avertissement
Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)