Constructors Summary |
---|
public Checkbox()Creates a check box with an empty string for its label.
The state of this check box is set to "off," and it is not
part of any check box group.
this("", false, null);
|
public Checkbox(String label)Creates a check box with the specified label. The state
of this check box is set to "off," and it is not part of
any check box group.
this(label, false, null);
|
public Checkbox(String label, boolean state)Creates a check box with the specified label
and sets the specified state.
This check box is not part of any check box group.
this(label, state, null);
|
public Checkbox(String label, boolean state, CheckboxGroup group)Constructs a Checkbox with the specified label, set to the
specified state, and in the specified check box group.
GraphicsEnvironment.checkHeadless();
this.label = label;
this.state = state;
this.group = group;
if (state && (group != null)) {
group.setSelectedCheckbox(this);
}
|
public Checkbox(String label, CheckboxGroup group, boolean state)Creates a check box with the specified label, in the specified
check box group, and set to the specified state.
this(label, state, group);
|
Methods Summary |
---|
public synchronized void | addItemListener(java.awt.event.ItemListener l)Adds the specified item listener to receive item events from
this check box. Item events are sent to listeners in response
to user input, 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. The peer allows you to change the
look of the Checkbox without changing its functionality.
synchronized (getTreeLock()) {
if (peer == null)
peer = getToolkit().createCheckbox(this);
super.addNotify();
}
|
java.lang.String | constructComponentName()Constructs a name for this component. Called by
getName when the name is null .
synchronized (getClass()) {
return base + nameCounter++;
}
|
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 Checkbox.
For checkboxes, the AccessibleContext takes the form of an
AccessibleAWTCheckbox.
A new AccessibleAWTCheckbox is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTCheckbox();
}
return accessibleContext;
|
public java.awt.CheckboxGroup | getCheckboxGroup()Determines this check box's group.
return group;
|
public synchronized java.awt.event.ItemListener[] | getItemListeners()Returns an array of all the item listeners
registered on this checkbox.
return (ItemListener[]) (getListeners(ItemListener.class));
|
public java.lang.String | getLabel()Gets the label of this check box.
return label;
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as FooListener s
upon this Checkbox .
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
Checkbox 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 java.lang.Object[] | getSelectedObjects()Returns an array (length 1) containing the checkbox
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 this check box is in the "on" or "off" state.
The boolean value true indicates the "on" state,
and false indicates the "off" state.
return state;
|
private static native void | initIDs()Initialize JNI field and method ids
|
protected java.lang.String | paramString()Returns a string representing the state of this Checkbox .
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 .
String str = super.paramString();
String label = this.label;
if (label != null) {
str += ",label=" + label;
}
return str + ",state=" + state;
|
protected void | processEvent(java.awt.AWTEvent e)Processes events on this check box.
If the event is an instance of ItemEvent ,
this method invokes the processItemEvent method.
Otherwise, it calls its superclass's processEvent method.
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 by
dispatching them to any registered
ItemListener objects.
This method is not called unless item events are
enabled for this component. 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)Reads the ObjectInputStream and if it
isn't null adds a listener to receive
item events fired by the Checkbox .
Unrecognized keys or values will be ignored.
GraphicsEnvironment.checkHeadless();
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 the item listener
no longer receives item events from this check box.
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 void | setCheckboxGroup(java.awt.CheckboxGroup g)Sets this check box's group to the specified check box group.
If this check box is already in a different check box group,
it is first taken out of that group.
If the state of this check box is true and the new
group already has a check box selected, this check box's state
is changed to false . If the state of this check
box is true and the new group has no check box
selected, this check box becomes the selected checkbox for
the new group and its state is true .
CheckboxGroup oldGroup;
boolean oldState;
/* Do nothing if this check box has already belonged
* to the check box group g.
*/
if (this.group == g) {
return;
}
synchronized (this) {
oldGroup = this.group;
oldState = getState();
this.group = g;
CheckboxPeer peer = (CheckboxPeer)this.peer;
if (peer != null) {
peer.setCheckboxGroup(g);
}
if (this.group != null && getState()) {
if (this.group.getSelectedCheckbox() != null) {
setState(false);
} else {
this.group.setSelectedCheckbox(this);
}
}
}
/* Locking check box below could cause deadlock with
* CheckboxGroup's setSelectedCheckbox method.
*
* Fix for 4726853 by kdm@sparc.spb.su
* Here we should check if this check box was selected
* in the previous group and set selected check box to
* null for that group if so.
*/
if (oldGroup != null && oldState) {
oldGroup.setSelectedCheckbox(null);
}
|
public void | setLabel(java.lang.String label)Sets this check box's label to be the string argument.
boolean testvalid = false;
synchronized (this) {
if (label != this.label && (this.label == null ||
!this.label.equals(label))) {
this.label = label;
CheckboxPeer peer = (CheckboxPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
testvalid = true;
}
}
// This could change the preferred size of the Component.
if (testvalid && valid) {
invalidate();
}
|
public void | setState(boolean state)Sets the state of this check box to the specified state.
The boolean value true indicates the "on" state,
and false indicates the "off" state.
Note that this method should be primarily used to
initialize the state of the checkbox. Programmatically
setting the state of the checkbox will not trigger
an ItemEvent . The only way to trigger an
ItemEvent is by user interaction.
/* Cannot hold check box lock when calling group.setSelectedCheckbox. */
CheckboxGroup group = this.group;
if (group != null) {
if (state) {
group.setSelectedCheckbox(this);
} else if (group.getSelectedCheckbox() == this) {
state = true;
}
}
setStateInternal(state);
|
void | setStateInternal(boolean state)Helper function for setState and CheckboxGroup.setSelectedCheckbox
Should remain package-private.
this.state = state;
CheckboxPeer peer = (CheckboxPeer)this.peer;
if (peer != null) {
peer.setState(state);
}
|
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);
|