|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.TriStateCheckBoxList
public class TriStateCheckBoxList
A component that allows the user to select one or more objects from a
list by using TriStateCheckBoxes 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 TriStateCheckBoxList
constructor that builds a ListModel
instance for you:
// Create a TriStateCheckBoxList that displays the strings in data[] String[] data = {"one", "two", "three", "four"}; TriStateCheckBoxList dataList = new TriStateCheckBoxList(data); // The value of the TriStateCheckBoxList 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 TriStateCheckBoxList that displays the superclass of TriStateCheckBoxList.class. // We store the superclasses in a java.util.Vector. Vector superClasses = new Vector(); Class rootClass = javax.swing.TriStateCheckBoxList.class; for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) { superClasses.addElement(cls); } TriStateCheckBoxList classList = new TriStateCheckBoxList(superClasses);
TriStateCheckBoxList
doesn't support scrolling directly.
To create a scrolling
list you make the TriStateCheckBoxList
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 TriStateCheckBoxList
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 TriStateCheckBoxList
provides convenient properties for
managing the selection.
String[] data = {"one", "two", "three", "four"}; TriStateCheckBoxList dataList = new TriStateCheckBoxList(data); dataList.setSelectedIndex(1); // select "two" as MIXED dataList.getSelectedValues(); // returns "two" dataList.setSelectedIndex(2); // select "three" as MIXED dataList.getSelectedValues(); // returns "two","three" dataList.setSelectedIndex(1); // select "two" as ON dataList.getSelectedValues(); // returns "two","three" dataList.setSelectedIndex(1); // select "two" as OFF dataList.getSelectedValues(); // returns "three"
Field Summary |
---|
Fields inherited from class com.sas.swing.visuals.CheckBoxList |
---|
RB_KEY |
Constructor Summary | |
---|---|
TriStateCheckBoxList()
Constructs a TriStateCheckBoxList with an empty model. |
|
TriStateCheckBoxList(javax.swing.ListModel dataModel)
Constructs a TriStateCheckBoxList that displays the elements in the
specified, non-null model. |
|
TriStateCheckBoxList(java.lang.Object[] listData)
Constructs a TriStateCheckBoxList that displays the elements in the specified
array. |
|
TriStateCheckBoxList(java.util.Vector listData)
Constructs a TriStateCheckBoxList that displays the elements in the specified
Vector . |
Method Summary | |
---|---|
int |
getSelectedIndexValue(int index)
Returns the value at the given index. |
boolean |
isCycleEnabled()
Returns whether the checkbox cycles through all three values. |
boolean |
isUpdateEnabled()
Used internally to return whether values can be updated. |
void |
setCycleEnabled(boolean b)
Sets whether each checkBox in the list should cycle through all three values. |
void |
setSelectedIndexValue(int index,
int value)
Sets the given index to the given value. |
void |
setUpdateEnabled(boolean b)
Used internally to set whether values can be updated. |
Methods inherited from class com.sas.swing.visuals.CheckBoxList |
---|
getExtendedBeanInfo, isBorderPaintedFlat, setBorderPaintedFlat, setSelectedIndices |
Constructor Detail |
---|
public TriStateCheckBoxList(javax.swing.ListModel dataModel)
TriStateCheckBoxList
that displays the elements in the
specified, non-null model. All TriStateCheckBoxList
constructors
delegate to this one.
dataModel
- the data model for this list
java.lang.IllegalArgumentException
- if dataModel
is null
public TriStateCheckBoxList(java.lang.Object[] listData)
TriStateCheckBoxList
that displays the elements in the specified
array. This constructor just delegates to the ListModel
constructor.
listData
- the array of Objects to be loaded into the data modelpublic TriStateCheckBoxList(java.util.Vector listData)
TriStateCheckBoxList
that displays the elements in the specified
Vector
. This constructor just delegates to the
ListModel
constructor.
listData
- the Vector
to be loaded into the data modelpublic TriStateCheckBoxList()
TriStateCheckBoxList
with an empty model.
Method Detail |
---|
public void setSelectedIndexValue(int index, int value)
index
- The index in which to changevalue
- The new value to be setpublic int getSelectedIndexValue(int index)
index
- The index to search on
public void setCycleEnabled(boolean b)
b
- if true, the checkBox cycles,
or else the checkBox switches between ON and OFF once those values
have been reached.public boolean isCycleEnabled()
public void setUpdateEnabled(boolean b)
public boolean isUpdateEnabled()
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |