CheckBoxTreeSelectionModel

Top  Previous  Next

 

CheckBoxTreeSelectionModel is the checkbox's selection model. It can be used to find out what tree nodes are selected and to select/deselect one or more nodes. CheckBoxTreeSelectionModel extends TreeSelectionModel, which defines the selection model for a JTree. The difference here is that while TreeSelectionModel treats paths as tree rows being selected, CheckBoxTreeSelectionModel's selections paths refer to the nodes whose checkbox is selected.

 

You can use TreeSelectionModel's methods to manage the checkboxes selection, just as you do for the tree rows selections.

 

For example, the method to retrieve all selected paths is:

 

public TreePath[] getSelectionPaths();

 

To find out if a specific path is selected:

 

public boolean isPathSelected(TreePath path);

 

To add a checkbox selection:

 

public void addSelectionPath(TreePath path);

 

To remove a checkbox selection:

 

public void removeSelectionPath(TreePath path);

 

To remove all selected paths:

 

public void clearSelection();

 

Install a listener that is notified every time a checkbox selection is changed:

 

public void addTreeSelectionListener(TreeSelectionListener x);