|
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.CheckBoxListWithSelectable
public class CheckBoxListWithSelectable
CheckBoxListWithSelectable
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.
Selectable
. If you have your own class that represents the
element in the list, you can implement Selectable
and implements a few very simple methods. If your
elements are already in an array or Vector that you pass in to the constructor of JList, we will convert them to
DefaultSelectable
which implements Selectable
interface.
To select an element, user can mouse click on the check box, or highlight the rows and press SPACE key to toggle the
selections.
To listen to the check box selection change, you can call addItemListener to add an ItemListener.
Please note, there are two implementations of CheckBoxList. CheckBoxListWithSelectable is one. There is also another
one call CheckBoxList. CheckBoxListWithSelectable is actually the old implementation. In 1.9.2, we introduced a new
implementation and renamed the old implementation to CheckBoxListWithSelectable. 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 CheckBoxList.getCheckBoxListSelectionModel()
. The old
implementation kept the selection state at Selectable object in the ListModel.
Nested Class Summary | |
---|---|
protected static class |
CheckBoxListWithSelectable.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 CheckBoxListCellRenderer |
_listCellRenderer
|
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 | |
---|---|
CheckBoxListWithSelectable()
Constructs a CheckBoxList with an empty model. |
|
CheckBoxListWithSelectable(ListModel dataModel)
Constructs a CheckBoxList that displays the elements in the specified, non-null model. |
|
CheckBoxListWithSelectable(Object[] listData)
Constructs a CheckBoxList that displays the elements in the specified Object[] . |
|
CheckBoxListWithSelectable(Vector<?> listData)
Constructs a CheckBoxList that displays the elements in the specified Vector . |
Method Summary | |
---|---|
void |
addItemListener(ItemListener listener)
Adds a listener to the list that's notified each time a change to the item selection occurs. |
protected CheckBoxListCellRenderer |
createCellRenderer()
Creates the cell renderer. |
protected CheckBoxListWithSelectable.Handler |
createHandler()
Creates the mouse listener and key listener used by CheckBoxList. |
protected void |
fireItemStateChanged(ItemEvent event)
Notifies all listeners that have registered interest for notification on this event type. |
ListCellRenderer |
getActualCellRenderer()
|
ListCellRenderer |
getCellRenderer()
|
ItemListener[] |
getItemListeners()
Returns an array of all the ItemListener s added to this JList with addItemListener(). |
int |
getNextMatch(String prefix,
int startIndex,
Position.Bias bias)
|
Object[] |
getSelectedObjects()
Gets the selected objects. |
protected void |
init()
Initialize the CheckBoxList. |
boolean |
isCheckBoxEnabled()
Gets the value of property checkBoxEnabled. |
boolean |
isCheckBoxVisible(int index)
Checks if check box is visible. |
boolean |
isClickInCheckBoxOnly()
Gets the value of property clickInCheckBoxOnly. |
void |
removeItemListener(ItemListener listener)
Removes a listener from the list that's notified each time a change to the item selection occurs. |
void |
selectAll()
Selects all objects in this list except those are disabled. |
void |
selectNone()
Deselects all objects in this list except those are disabled. |
void |
setCheckBoxEnabled(boolean checkBoxEnabled)
Sets the value of property checkBoxEnabled. |
void |
setClickInCheckBoxOnly(boolean clickInCheckBoxOnly)
Sets the value of property clickInCheckBoxOnly. |
void |
setListData(Object[] listData)
|
void |
setListData(Vector listData)
|
void |
setSelectedObjects(Object[] elements)
Sets the selected elements. |
void |
setSelectedObjects(Vector<?> objects)
Sets the selected objects. |
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
Constructor Detail |
---|
public CheckBoxListWithSelectable()
CheckBoxList
with an empty model.
public CheckBoxListWithSelectable(Vector<?> listData)
CheckBoxList
that displays the elements in the specified Vector
. If the
Vector contains elements which is not an instance of Selectable
, it will wrap it automatically into
DefaultSelectable
and add to ListModel.
listData
- the Vector
to be loaded into the data modelpublic CheckBoxListWithSelectable(Object[] listData)
CheckBoxList
that displays the elements in the specified Object[]
. If the
Object array contains elements which is not an instance of Selectable
, it will wrap it automatically into
DefaultSelectable
and add to ListModel.
listData
- the array of Objects to be loaded into the data modelpublic CheckBoxListWithSelectable(ListModel dataModel)
CheckBoxList
that displays the elements in the specified, non-null
model.
All CheckBoxList
constructors delegate to this one.
Please note, if you are using this constructor, please make sure all elements in dataModel are instance of Selectable
.
dataModel
- the data model for this list
IllegalArgumentException
- if dataModel
is null
Method Detail |
---|
protected void init()
protected CheckBoxListCellRenderer createCellRenderer()
protected CheckBoxListWithSelectable.Handler createHandler()
public void setSelectedObjects(Object[] elements)
elements
- the elements to be selectedpublic void setSelectedObjects(Vector<?> objects)
objects
- the elements to be selected in a Vector.public ListCellRenderer getCellRenderer()
getCellRenderer
in class JList
public ListCellRenderer getActualCellRenderer()
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 void addItemListener(ItemListener listener)
CheckBoxList
will have their ItemEvent.getSource() == this
CheckBoxList
.
addItemListener
in interface ItemSelectable
listener
- the ItemListener
to addpublic void removeItemListener(ItemListener listener)
removeItemListener
in interface ItemSelectable
listener
- the ItemListener
to removepublic ItemListener[] getItemListeners()
ItemListener
s added to this JList with addItemListener().
ItemListener
s added or an empty array if no listeners have been addedaddItemListener(java.awt.event.ItemListener)
protected void fireItemStateChanged(ItemEvent event)
event
parameter.
event
- the ItemEvent
objectEventListenerList
public Object[] getSelectedObjects()
JList.getSelectedValues()
which is a JList's feature. The
List returned from this method contains the objects that is checked in the CheckBoxList.
getSelectedObjects
in interface ItemSelectable
public void selectAll()
public void selectNone()
public void setListData(Vector listData)
setListData
in class JList
public void setListData(Object[] listData)
setListData
in class JList
public int getNextMatch(String prefix, int startIndex, Position.Bias bias)
getNextMatch
in class JList
public boolean isCheckBoxEnabled()
public boolean isCheckBoxVisible(int index)
index
- the row index.
public void setCheckBoxEnabled(boolean checkBoxEnabled)
checkBoxEnabled
- true to enable all the check boxes. False to disable all of them.
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |