com.sas.swing.visuals
Class CheckBoxList

com.sas.swing.visuals.CheckBoxList
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable
Direct Known Subclasses:
TriStateCheckBoxList

public class CheckBoxList

A component that allows the user to select one or more objects from a list by using checkboxes in place of labels. A separate model, ListModel, represents the contents of the list. It's easy to display an array or vector of objects, using a CheckBoxList constructor that builds a ListModel instance for you:

 // Create a CheckBoxList that displays the strings in data[]

 String[] data = {"one", "two", "three", "four"};
 CheckBoxList dataList = new CheckBoxList(data);
 
 // The value of the CheckBoxList model property is an object that provides
 // a read-only view of the data.  It was constructed automatically.

 for(int i = 0; i < dataList.getModel().getSize(); i++) {
     System.out.println(dataList.getModel().getElementAt(i));
 }

 // Create a CheckBoxList that displays the superclass of CheckBoxList.class.
 // We store the superclasses in a java.util.Vector.

 Vector superClasses = new Vector();
 Class rootClass = javax.swing.CheckBoxList.class;
 for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) {
     superClasses.addElement(cls);
 }
 CheckBoxList classList = new CheckBoxList(superClasses);
 

CheckBoxList doesn't support scrolling directly. To create a scrolling list you make the CheckBoxList the viewport view of a JScrollPane. For example:

 JScrollPane scrollPane = new JScrollPane(dataList);
 // Or in two steps:
 JScrollPane scrollPane = new JScrollPane();
 scrollPane.getViewport().setView(dataList);
 

By default the CheckBoxList selection model allows any combination of items to be selected at a time, using the constant MULTIPLE_INTERVAL_SELECTION. The selection state is actually managed by a separate delegate object, an instance of ListSelectionModel. However CheckBoxList provides convenient properties for managing the selection.

 String[] data = {"one", "two", "three", "four"};
 CheckBoxList dataList = new CheckBoxList(data);

 dataList.setSelectedIndex(1);  // select "two"
 dataList.getSelectedValues();   // returns "two"
 dataList.setSelectedIndex(2);  // select "three"
 dataList.getSelectedValues();   // returns "two","three"
 dataList.setSelectedIndex(1);  // select "two" which deselects it since it was already selected
 dataList.getSelectedValues();   // returns "three"
 

See Also:
Serialized Form

Field Summary
static java.lang.String RB_KEY
           
 
Constructor Summary
CheckBoxList()
          Constructs a CheckBoxList with an empty model.
CheckBoxList(javax.swing.ListModel dataModel)
          Constructs a CheckBoxList that displays the elements in the specified, non-null model.
CheckBoxList(java.lang.Object[] listData)
          Constructs a CheckBoxList that displays the elements in the specified array.
CheckBoxList(java.util.Vector listData)
          Constructs a CheckBoxList that displays the elements in the specified Vector.
 
Method Summary
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this CheckBoxList.
 boolean isBorderPaintedFlat()
          Returns whether the checkbox border is painted flat.
 void setBorderPaintedFlat(boolean b)
          Sets whether the border should be painted flat.
 void setSelectedIndices(int[] indices)
          Selects a set of cells.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values
Constructor Detail

CheckBoxList

public CheckBoxList(javax.swing.ListModel dataModel)
Constructs a CheckBoxList that displays the elements in the specified, non-null model. All CheckBoxList constructors delegate to this one.

Parameters:
dataModel - the data model for this list
Throws:
java.lang.IllegalArgumentException - if dataModel is null

CheckBoxList

public CheckBoxList(java.lang.Object[] listData)
Constructs a CheckBoxList that displays the elements in the specified array. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the array of Objects to be loaded into the data model

CheckBoxList

public CheckBoxList(java.util.Vector listData)
Constructs a CheckBoxList that displays the elements in the specified Vector. This constructor just delegates to the ListModel constructor.

Parameters:
listData - the Vector to be loaded into the data model

CheckBoxList

public CheckBoxList()
Constructs a CheckBoxList with an empty model.

Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this CheckBoxList.

Returns:
the ExtendedBeanInfo for this class

setSelectedIndices

public void setSelectedIndices(int[] indices)
Selects a set of cells.

Overrides:
setSelectedIndices in class javax.swing.JList
Parameters:
indices - an array of the indices of the cells to select
See Also:
ListSelectionModel.setSelectionInterval(int, int)

setBorderPaintedFlat

public void setBorderPaintedFlat(boolean b)
Sets whether the border should be painted flat.

Parameters:
b - if true, the border is painted flat.

isBorderPaintedFlat

public boolean isBorderPaintedFlat()
Returns whether the checkbox border is painted flat.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.