All Packages Class Hierarchy This Package Previous Next Index
Class jclass.bwt.JCCheckboxGroup
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----jclass.bwt.JCContainer
|
+----jclass.bwt.JCGroupBox
|
+----jclass.bwt.JCCheckboxGroup
- public class JCCheckboxGroup
- extends JCGroupBox
- implements JCItemSelectable
Creates a box for a set of JCCheckbox buttons. By default, all the buttons
are given a radio-button style, and only one is "on" at a time.
The AWT CheckboxGroup class does not allow access to the
checkboxes it manages. This makes the task of manipulating
checkbox groups awkward. JCCheckboxGroup stores the checkboxes in a list.
Properties
Events
Class | Listener | Description |
JCItemEvent | addItemListener | Posted when the button's state changes |
Example:
public myForm extends Panel {
int colorValues = { BLUE, GREEN, VIOLET };
String colorStrings = {"Blue", "Green", "Violet"};
JCCheckbox colorG;
public myForm() {
add(colorG = JCCheckbox.makeGroup(colorStrings, colorValues, true));
}
private int getColor();
private void setColor(int);
public void getData() {
colorG.set(colorValues, getColor());
}
public void setData() {
setColor(colorG.getCurrentJC().value);
}
}
If items change, simply change the colorValues and colorStrings arrays.
-
boxes
- The child checkboxes.
-
current
- The current choice.
-
HORIZONTAL
-
-
itemListeners
- List of JCItemEvent listeners
-
VERTICAL
-
-
JCCheckboxGroup()
- Creates an empty vertical group which uses a GridLayout
with insets of (5,5,5,5).
-
JCCheckboxGroup(Applet, String)
- Creates an empty vertical group which uses a GridLayout with insets of (5,5,5,5).
-
JCCheckboxGroup(Object)
- Creates an empty vertical group with the specified title.
-
add(JCCheckbox)
- Adds a checkbox to the list of managed checkboxes.
-
addItemListener(JCItemListener)
- Adds the specified item listener to receive item events from the checkboxes.
-
addNotify()
- If RadioBehavior is true and no button has been set, set the first.
-
getCheckbox(int)
- Gets the checkbox at the specified index.
-
getCurrent()
- Gets the currently-selected checkbox.
-
getOrientation()
- Gets the orientation.
-
getParameters()
- Reads the parameter values from the HTML page using the component's applet.
-
getRadioBehavior()
- Gets the RadioBehavior value.
-
getSelected()
- Returns a list of the positions of all buttons whose state is ON.
-
getSelectedIndexes()
- Returns a list of the indices of the selected checkboxes,
or null if no checkboxes are selected.
-
getSelectedObjects()
- Returns the a list of the labels of the selected checkboxes,
or null if no checkboxes are selected.
-
getValue()
- Gets the current checkbox's UserData as an int.
-
manage(JCCheckbox)
- Adds a checkbox to the list of managed checkboxes.
-
numCheckboxes()
- Returns the number of Checkbox instances that have been added.
-
removeItemListener(JCItemListener)
- Removes the specified item listener so it no longer receives
item events from the checkboxes.
-
setCurrent(JCCheckbox)
- Sets the current choice to the specified checkbox, whose state is set
to BWTEnum.ON.
-
setOrientation(int)
- Sets the layout direction: VERTICAL (default) or HORIZONTAL.
HTML param name/value: "Orientation"/enum
-
setRadioBehavior(boolean)
- If set to true (default), a RadioBox-type behavior is enforced on
all Checkboxes.
-
setValue(int)
- Sets the group's current checkbox to the first checkbox whose UserData
is the specified value.
-
setValue(int[], int)
- Sets the currently-selected checkbox to that containing the
value "val".
HORIZONTAL
public static final int HORIZONTAL
VERTICAL
public static final int VERTICAL
boxes
protected JCVector boxes
- The child checkboxes.
current
protected JCCheckbox current
- The current choice.
itemListeners
protected JCVector itemListeners
- List of JCItemEvent listeners
JCCheckboxGroup
public JCCheckboxGroup()
- Creates an empty vertical group which uses a GridLayout
with insets of (5,5,5,5).
No parameters are read from an HTML file.
JCCheckboxGroup
public JCCheckboxGroup(Object title)
- Creates an empty vertical group with the specified title.
No parameters are read from an HTML file.
- Parameters:
- title - a String, Image, JCString, or any object (in which case the object's toString() method is called to obtain a string)
- See Also:
- setTitle
JCCheckboxGroup
public JCCheckboxGroup(Applet applet,
String name)
- Creates an empty vertical group which uses a GridLayout with insets of (5,5,5,5).
Parameters are read from the applet's HTML file.
- Parameters:
- applet - the applet whose PARAM tags are to be read
- name - if this is not null, only parameters preceded by this name are read
- See Also:
- getParameter, GridLayout, setInsets
getParameters
protected void getParameters()
- Reads the parameter values from the HTML page using the component's applet.
The values will override those previously set.
- Overrides:
- getParameters in class JCGroupBox
add
public Component add(JCCheckbox box)
- Adds a checkbox to the list of managed checkboxes. The checkbox is added
to this container. To specify that a checkbox be managed which is not a
child of this group, use JCCheckbox.setCheckboxGroup() or manage
- See Also:
- setCheckboxGroup, manage
manage
public void manage(JCCheckbox box)
- Adds a checkbox to the list of managed checkboxes. The checkbox is not added
to this container.
- See Also:
- add
numCheckboxes
public int numCheckboxes()
- Returns the number of Checkbox instances that have been added.
- See Also:
- add
getCheckbox
public JCCheckbox getCheckbox(int i)
- Gets the checkbox at the specified index.
getOrientation
public int getOrientation()
- Gets the orientation.
- See Also:
- setOrientation
setOrientation
public void setOrientation(int v)
- Sets the layout direction: VERTICAL (default) or HORIZONTAL.
HTML param name/value: "Orientation"/enum
- See Also:
- toEnum
getCurrent
public JCCheckbox getCurrent()
- Gets the currently-selected checkbox.
- See Also:
- setCurrent
getSelectedIndexes
public int[] getSelectedIndexes()
- Returns a list of the indices of the selected checkboxes,
or null if no checkboxes are selected.
- See Also:
- getCheckbox, getSelectedObjects
getSelectedObjects
public Object[] getSelectedObjects()
- Returns the a list of the labels of the selected checkboxes,
or null if no checkboxes are selected.
- See Also:
- getSelectedIndexes
setCurrent
public synchronized void setCurrent(JCCheckbox box)
- Sets the current choice to the specified checkbox, whose state is set
to BWTEnum.ON.
If RadioBehavior has been set, the previously current button is unselected.
- Parameters:
- box - if this button belongs to a different group, there is no effect
- See Also:
- setRadioBehavior
getRadioBehavior
public boolean getRadioBehavior()
- Gets the RadioBehavior value.
- See Also:
- setRadioBehavior
setRadioBehavior
public void setRadioBehavior(boolean v)
- If set to true (default), a RadioBox-type behavior is enforced on
all Checkboxes. When one button is selected and another is set interactively
or programmatically, the first button is unselected automatically.
The checkboxGroup will set the indicator of any checkbox whose indicator
has not been set explicitly via setIndicator:
- If set to true, the Checkbox's indicator is set to INDICATOR_CIRCLE.
- If set to false, the Checkbox's indicator is set to INDICATOR_CROSS.
This value may be set in an HTML file using the PARAM name "RadioBehavior"
with a boolean value.
- See Also:
- setCurrent, setState, setIndicator, toBoolean
getValue
public int getValue()
- Gets the current checkbox's UserData as an int. If the current button
has no UserData value, 0 is returned.
- Returns:
- BWTEnum.NOTFOUND if no button is selected
- See Also:
- setValue, JCCheckbox, getUserDataInt
setValue
public boolean setValue(int value)
- Sets the group's current checkbox to the first checkbox whose UserData
is the specified value.
- Returns:
- false if no button could be found which matches the value
- See Also:
- getValue
addItemListener
public void addItemListener(JCItemListener l)
- Adds the specified item listener to receive item events from the checkboxes.
- See Also:
- JCItemEvent
removeItemListener
public void removeItemListener(JCItemListener l)
- Removes the specified item listener so it no longer receives
item events from the checkboxes.
getSelected
public int[] getSelected()
- Returns a list of the positions of all buttons whose state is ON.
setValue
public void setValue(int values[],
int val)
- Sets the currently-selected checkbox to that containing the
value "val". Typically, using JCCheckbox and JCCheckboxGroup
involves creating an array representing values assigned to each
checkbox. This function takes the array and the desired value,
finds the checkbox item, and makes that checkbox the current item.
This makes it relatively easy to set checkbox values based on user
data. For example:
int boxValues[] = { BLUE, GREEN, VIOLET };
JCCheckboxGroup boxG;
public getColor() {
boxG.set(boxValues, myObject.getColor());
}
addNotify
public void addNotify()
- If RadioBehavior is true and no button has been set, set the first.
- Overrides:
- addNotify in class JCGroupBox
All Packages Class Hierarchy This Package Previous Next Index