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

Name Method
Background setBackground
Font setFont
Foreground setForeground
Insets setInsets
Orientation setOrientation
PreferredSize setPreferredSize
RadioBehavior setRadioBehavior
UserData setUserData

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.


Variable Index

 o boxes
The child checkboxes.
 o current
The current choice.
 o HORIZONTAL
 o itemListeners
List of JCItemEvent listeners
 o VERTICAL

Constructor Index

 o JCCheckboxGroup()
Creates an empty vertical group which uses a GridLayout with insets of (5,5,5,5).
 o JCCheckboxGroup(Applet, String)
Creates an empty vertical group which uses a GridLayout with insets of (5,5,5,5).
 o JCCheckboxGroup(Object)
Creates an empty vertical group with the specified title.

Method Index

 o add(JCCheckbox)
Adds a checkbox to the list of managed checkboxes.
 o addItemListener(JCItemListener)
Adds the specified item listener to receive item events from the checkboxes.
 o addNotify()
If RadioBehavior is true and no button has been set, set the first.
 o getCheckbox(int)
Gets the checkbox at the specified index.
 o getCurrent()
Gets the currently-selected checkbox.
 o getOrientation()
Gets the orientation.
 o getParameters()
Reads the parameter values from the HTML page using the component's applet.
 o getRadioBehavior()
Gets the RadioBehavior value.
 o getSelected()
Returns a list of the positions of all buttons whose state is ON.
 o getSelectedIndexes()
Returns a list of the indices of the selected checkboxes, or null if no checkboxes are selected.
 o getSelectedObjects()
Returns the a list of the labels of the selected checkboxes, or null if no checkboxes are selected.
 o getValue()
Gets the current checkbox's UserData as an int.
 o manage(JCCheckbox)
Adds a checkbox to the list of managed checkboxes.
 o numCheckboxes()
Returns the number of Checkbox instances that have been added.
 o removeItemListener(JCItemListener)
Removes the specified item listener so it no longer receives item events from the checkboxes.
 o setCurrent(JCCheckbox)
Sets the current choice to the specified checkbox, whose state is set to BWTEnum.ON.
 o setOrientation(int)
Sets the layout direction: VERTICAL (default) or HORIZONTAL.

HTML param name/value: "Orientation"/enum

 o setRadioBehavior(boolean)
If set to true (default), a RadioBox-type behavior is enforced on all Checkboxes.
 o setValue(int)
Sets the group's current checkbox to the first checkbox whose UserData is the specified value.
 o setValue(int[], int)
Sets the currently-selected checkbox to that containing the value "val".

Variables

 o HORIZONTAL
 public static final int HORIZONTAL
 o VERTICAL
 public static final int VERTICAL
 o boxes
 protected JCVector boxes
The child checkboxes.

 o current
 protected JCCheckbox current
The current choice.

 o itemListeners
 protected JCVector itemListeners
List of JCItemEvent listeners

Constructors

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

 o 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
 o 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

Methods

 o 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
 o 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
 o 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
 o numCheckboxes
 public int numCheckboxes()
Returns the number of Checkbox instances that have been added.

See Also:
add
 o getCheckbox
 public JCCheckbox getCheckbox(int i)
Gets the checkbox at the specified index.

 o getOrientation
 public int getOrientation()
Gets the orientation.

See Also:
setOrientation
 o setOrientation
 public void setOrientation(int v)
Sets the layout direction: VERTICAL (default) or HORIZONTAL.

HTML param name/value: "Orientation"/enum

See Also:
toEnum
 o getCurrent
 public JCCheckbox getCurrent()
Gets the currently-selected checkbox.

See Also:
setCurrent
 o 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
 o 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
 o 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
 o getRadioBehavior
 public boolean getRadioBehavior()
Gets the RadioBehavior value.

See Also:
setRadioBehavior
 o 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:

This value may be set in an HTML file using the PARAM name "RadioBehavior" with a boolean value.

See Also:
setCurrent, setState, setIndicator, toBoolean
 o 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
 o 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
 o addItemListener
 public void addItemListener(JCItemListener l)
Adds the specified item listener to receive item events from the checkboxes.

See Also:
JCItemEvent
 o removeItemListener
 public void removeItemListener(JCItemListener l)
Removes the specified item listener so it no longer receives item events from the checkboxes.

 o getSelected
 public int[] getSelected()
Returns a list of the positions of all buttons whose state is ON.

 o 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());
}

 o 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