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.
To select an element, user can mouse click on the check box, or highlight the rows and press SPACE key to toggle the selections.
We used cell renderer feature in JList to add the check box in each row. However you can still set your own cell renderer just like before using {@link #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 {@link CheckBoxList#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_ENTRY 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 {@link 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 {@link CheckBoxList#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 {@link CheckBoxTree}.