|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JList com.jidesoft.swing.CheckBoxList
public class CheckBoxList
CheckBoxList
is a special JList which uses JCheckBox as the list element. In addition to regular JList
feature, it also allows you select any number of elements in the list by selecting the check boxes.
JList.setCellRenderer(javax.swing.ListCellRenderer)
. CheckBoxList will use your
cell renderer and automatically put a check box before it.
The selection state is kept in a ListSelectionModel called CheckBoxListSelectionModel, which you can get using getCheckBoxListSelectionModel()
. If you need to add a check to a check box or to find out if a check
box is checked, you need to ask the getCheckBoxListSelectionModel() by using addListSelectionListener.
It is possible to add an "(All)" item. All you need to do is to add CheckBoxList.ALL to the list model. Then check
the (All) item will select all the check boxes and uncheck it will deselect all.
Please note, we changed CheckBoxList implementation in 1.9.2 release. The old CheckBoxList class is renamed to CheckBoxListWithSelectable
. If you want to use the old implementation, you can use CheckBoxListWithSelectable
instead. The main difference between the two implementation is at how the selection state is kept. In new
implementation, the selection state is kept at a separate ListSelectionModel which you can get using getCheckBoxListSelectionModel()
. If you need to add a check to a check box or to find out if a check
box is checked, you need to ask the getCheckBoxListSelectionModel() by using addListSelectionListener. The old
implementation kept the selection state at Selectable object in the ListModel. The new implementation also has the
same design as that of CheckBoxTree
.
Nested Class Summary | |
---|---|
protected static class |
CheckBoxList.Handler
|
Nested classes/interfaces inherited from class javax.swing.JList |
---|
JList.AccessibleJList, JList.DropLocation |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected CheckBoxList.Handler |
_handler
|
protected CheckBoxListCellRenderer |
_listCellRenderer
|
static String |
ALL
Deprecated. replaced by ALL_ENTRY |
static Object |
ALL_ENTRY
The default all entry for CheckBoxList. |
static String |
PROPERTY_CHECKBOX_ENABLED
|
static String |
PROPERTY_CLICK_IN_CHECKBOX_ONLY
|
Fields inherited from class javax.swing.JList |
---|
HORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAP |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
CheckBoxList()
Constructs a CheckBoxList with an empty model. |
|
CheckBoxList(ListModel dataModel)
Constructs a CheckBoxList that displays the elements in the specified, non-null model. |
|
CheckBoxList(Object[] listData)
Constructs a CheckBoxList that displays the elements in the specified Object[] . |
|
CheckBoxList(Vector<?> listData)
Constructs a CheckBoxList that displays the elements in the specified Vector . |
Method Summary | |
---|---|
void |
addCheckBoxListSelectedIndex(int index)
Selects a single cell and keeps all previous selections. |
void |
addCheckBoxListSelectedValue(Object anObject,
boolean shouldScroll)
Selects the specified object from the list and keep all previous selections. |
void |
addCheckBoxListSelectedValues(Object[] objects)
Selects the specified objects from the list and keep all previous selections. |
void |
clearCheckBoxListSelection()
|
protected CheckBoxListCellRenderer |
createCellRenderer()
Creates the cell renderer. |
protected CheckBoxListSelectionModel |
createCheckBoxListSelectionModel(ListModel model)
|
protected CheckBoxList.Handler |
createHandler()
Creates the mouse listener and key listener used by CheckBoxList. |
ListCellRenderer |
getActualCellRenderer()
|
ListCellRenderer |
getCellRenderer()
|
int |
getCheckBoxListSelectedIndex()
Returns the first selected index; returns -1 if there is no selected item. |
int[] |
getCheckBoxListSelectedIndices()
Returns an array of all of the selected indices in increasing order. |
Object |
getCheckBoxListSelectedValue()
Returns the first selected value, or null if the selection is empty. |
Object[] |
getCheckBoxListSelectedValues()
Returns an array of the values for the selected cells. |
CheckBoxListSelectionModel |
getCheckBoxListSelectionModel()
Gets the ListSelectionModel that keeps the check boxes' state information for CheckBoxList. |
int |
getLastVisibleIndex()
|
int |
getNextMatch(String prefix,
int startIndex,
Position.Bias bias)
|
Dimension |
getPreferredScrollableViewportSize()
|
protected void |
init()
Initialize the CheckBoxList. |
boolean |
isCheckBoxEnabled()
Gets the value of property checkBoxEnabled. |
boolean |
isCheckBoxEnabled(int index)
Checks if check box is enabled. |
boolean |
isCheckBoxVisible(int index)
Checks if check box is visible. |
boolean |
isClickInCheckBoxOnly()
Gets the value of property clickInCheckBoxOnly. |
void |
removeCheckBoxListSelectedIndex(int index)
Deselects a single cell. |
void |
removeCheckBoxListSelectedValue(Object anObject,
boolean shouldScroll)
Deselects the specified object from the list. |
void |
removeCheckBoxListSelectedValues(Object[] objects)
Deselects the specified objects from the list and keep all previous selections. |
void |
selectAll()
Selects all objects in this list. |
void |
selectNone()
Deselects all objects in this list. |
void |
setCheckBoxEnabled(boolean checkBoxEnabled)
Sets the value of property checkBoxEnabled. |
void |
setCheckBoxListSelectedIndex(int index)
Selects a single cell and clear all other selections. |
void |
setCheckBoxListSelectedIndices(int[] indices)
Selects a set of cells. |
void |
setCheckBoxListSelectedValue(Object anObject,
boolean shouldScroll)
Selects the specified object from the list and clear all other selections. |
void |
setCheckBoxListSelectionModel(CheckBoxListSelectionModel checkBoxListSelectionModel)
|
void |
setClickInCheckBoxOnly(boolean clickInCheckBoxOnly)
Sets the value of property clickInCheckBoxOnly. |
void |
setModel(ListModel model)
|
void |
setSelectedObjects(Object[] elements)
Sets the selected elements. |
void |
setSelectedObjects(Vector<?> elements)
Sets the selected elements. |
void |
updateUI()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CheckBoxListCellRenderer _listCellRenderer
public static final String PROPERTY_CHECKBOX_ENABLED
public static final String PROPERTY_CLICK_IN_CHECKBOX_ONLY
protected CheckBoxList.Handler _handler
@Deprecated public static final String ALL
ALL_ENTRY
public static final Object ALL_ENTRY
Constructor Detail |
---|
public CheckBoxList()
CheckBoxList
with an empty model.
public CheckBoxList(Vector<?> listData)
CheckBoxList
that displays the elements in the specified Vector
.
listData
- the Vector
to be loaded into the data modelpublic CheckBoxList(Object[] listData)
CheckBoxList
that displays the elements in the specified Object[]
.
listData
- the array of Objects to be loaded into the data modelpublic CheckBoxList(ListModel dataModel)
CheckBoxList
that displays the elements in the specified, non-null
model.
All CheckBoxList
constructors delegate to this one.
dataModel
- the data model for this list
IllegalArgumentException
- if dataModel
is null
Method Detail |
---|
public void setModel(ListModel model)
setModel
in class JList
public void updateUI()
updateUI
in class JList
protected void init()
public int getLastVisibleIndex()
getLastVisibleIndex
in class JList
protected CheckBoxListSelectionModel createCheckBoxListSelectionModel(ListModel model)
protected CheckBoxListCellRenderer createCellRenderer()
protected CheckBoxList.Handler createHandler()
public ListCellRenderer getCellRenderer()
getCellRenderer
in class JList
public ListCellRenderer getActualCellRenderer()
public int getNextMatch(String prefix, int startIndex, Position.Bias bias)
getNextMatch
in class JList
public boolean isCheckBoxEnabled(int index)
index
- the row index.
public boolean isCheckBoxVisible(int index)
index
- whether the check box on the row index is visible.
public boolean isCheckBoxEnabled()
public void setCheckBoxEnabled(boolean checkBoxEnabled)
checkBoxEnabled
- true to allow to check the check box. False to disable it which means user can see whether
a row is checked or not but they cannot change it.public boolean isClickInCheckBoxOnly()
public void setClickInCheckBoxOnly(boolean clickInCheckBoxOnly)
clickInCheckBoxOnly
- true to allow to check the check box. False to disable it which means user can see
whether a row is checked or not but they cannot change it.public CheckBoxListSelectionModel getCheckBoxListSelectionModel()
public void setCheckBoxListSelectionModel(CheckBoxListSelectionModel checkBoxListSelectionModel)
public int[] getCheckBoxListSelectedIndices()
JList.removeSelectionInterval(int, int)
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setCheckBoxListSelectedIndex(int index)
index
- the index of the one cell to selectListSelectionModel.setSelectionInterval(int, int)
,
JList.isSelectedIndex(int)
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void addCheckBoxListSelectedIndex(int index)
index
- the index of the one cell to selectListSelectionModel.setSelectionInterval(int, int)
,
JList.isSelectedIndex(int)
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void removeCheckBoxListSelectedIndex(int index)
index
- the index of the one cell to selectListSelectionModel.setSelectionInterval(int, int)
,
JList.isSelectedIndex(int)
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setCheckBoxListSelectedIndices(int[] indices)
indices
- an array of the indices of the cells to selectListSelectionModel.addSelectionInterval(int, int)
,
JList.isSelectedIndex(int)
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectedObjects(Object[] elements)
elements
- sets the select elements. All the rows that have the value in the array will be checked.public void setSelectedObjects(Vector<?> elements)
elements
- sets the select elements. All the rows that have the value in the Vector will be checked.public Object[] getCheckBoxListSelectedValues()
JList.isSelectedIndex(int)
,
JList.getModel()
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public int getCheckBoxListSelectedIndex()
getMinSelectionIndex
JList.getMinSelectionIndex()
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public Object getCheckBoxListSelectedValue()
null
if the selection is empty.
JList.getMinSelectionIndex()
,
JList.getModel()
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setCheckBoxListSelectedValue(Object anObject, boolean shouldScroll)
anObject
- the object to selectshouldScroll
- true if the list should scroll to display the selected object, if one exists; otherwise
falsepublic void addCheckBoxListSelectedValue(Object anObject, boolean shouldScroll)
anObject
- the object to be selectedshouldScroll
- true if the list should scroll to display the selected object, if one exists; otherwise
falsepublic void addCheckBoxListSelectedValues(Object[] objects)
objects
- the objects to be selectedpublic void removeCheckBoxListSelectedValues(Object[] objects)
objects
- the objects to be selectedpublic void removeCheckBoxListSelectedValue(Object anObject, boolean shouldScroll)
anObject
- the object to selectshouldScroll
- true if the list should scroll to display the selected object, if one exists; otherwise
falsepublic void clearCheckBoxListSelection()
public void selectAll()
public void selectNone()
public Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize
in interface Scrollable
getPreferredScrollableViewportSize
in class JList
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |