Methods Summary |
---|
public synchronized void | addItemListener(java.awt.event.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.
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.add(itemListener, l);
newEventsOnly = true;
|
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.
synchronized (getTreeLock()) {
if (peer == null)
peer = Toolkit.getDefaultToolkit().createCheckboxMenuItem(this);
super.addNotify();
}
|
java.lang.String | constructComponentName()Construct a name for this MenuComponent. Called by getName() when
the name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
|
void | doMenuEvent(long when, int modifiers)
setState(!state);
Toolkit.getEventQueue().postEvent(
new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
getLabel(),
state ? ItemEvent.SELECTED :
ItemEvent.DESELECTED));
|
boolean | eventEnabled(java.awt.AWTEvent e)
if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
itemListener != null) {
return true;
}
return false;
}
return super.eventEnabled(e);
|
public javax.accessibility.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.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTCheckboxMenuItem();
}
return accessibleContext;
|
public synchronized java.awt.event.ItemListener[] | getItemListeners()Returns an array of all the item listeners
registered on this checkbox menuitem.
return (ItemListener[])(getListeners(ItemListener.class));
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as FooListener s
upon this CheckboxMenuItem .
FooListener s 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.
EventListener l = null;
if (listenerType == ItemListener.class) {
l = itemListener;
} else {
return super.getListeners(listenerType);
}
return AWTEventMulticaster.getListeners(l, listenerType);
|
public synchronized java.lang.Object[] | getSelectedObjects()Returns the an array (length 1) containing the checkbox menu item
label or null if the checkbox is not selected.
if (state) {
Object[] items = new Object[1];
items[0] = label;
return items;
}
return null;
|
public boolean | getState()Determines whether the state of this check box menu item
is "on" or "off."
return state;
|
private static native void | initIDs()Initialize JNI field and method IDs
|
public java.lang.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 .
return super.paramString() + ",state=" + state;
|
protected void | processEvent(java.awt.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.
if (e instanceof ItemEvent) {
processItemEvent((ItemEvent)e);
return;
}
super.processEvent(e);
|
protected void | processItemEvent(java.awt.event.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.
ItemListener listener = itemListener;
if (listener != null) {
listener.itemStateChanged(e);
}
|
private void | readObject(java.io.ObjectInputStream s)
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (itemListenerK == key)
addItemListener((ItemListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
|
public synchronized void | removeItemListener(java.awt.event.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.
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.remove(itemListener, l);
|
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.
state = b;
CheckboxMenuItemPeer peer = (CheckboxMenuItemPeer)this.peer;
if (peer != null) {
peer.setState(b);
}
|
private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to stream. Writes
a list of serializable ItemListeners
as optional data. The non-serializable
ItemListeners are detected and
no attempt is made to serialize them.
s.defaultWriteObject();
AWTEventMulticaster.save(s, itemListenerK, itemListener);
s.writeObject(null);
|