title: JavaFX CheckBoxTreeItem Selection
body: <p>I have a javafx checkbox tree. I need to select the checkbox when the tree item is clicked. I have added a listener for the selection property of the tree view. But the listener gets fired only when the tree item is clicked. The above listener is not fired when the checkbox is clicked.</p>
  
  <p>Required: A listener that fires when a tree item or checkbox is clicked in the treeview.</p>
  
  <p>Code:</p>
  
  <pre><code>String memberArray = {"subChild1", "subChild2", "childSub1"}
  Group groupRoot = new Group();
  Scene scene = new Scene(groupRoot, Color.ALICEBLUE);
  HBox hBox = new HBox();
  hBox.setMaxWidth(fxPanel.getWidth());
  final Label royalLabel = new Label("Select a item");
  
  TreeSet&lt;String&gt; prefixMember = new TreeSet&lt;String&gt;();
  String tmpName = null;
  LinkedHashSet&lt;CheckBoxTreeItem&lt;String&gt;&gt; treeItems = new LinkedHashSet&lt;CheckBoxTreeItem&lt;String&gt;&gt;();
  LinkedHashSet&lt;CheckBoxTreeItem&lt;String&gt;&gt; treeSubItems = new LinkedHashSet&lt;CheckBoxTreeItem&lt;String&gt;&gt;();
  
  for (String item : memberArray) {
      if (!item.isEmpty()) {
          tmpName = item.substring(0, 3);
          prefixMember.add(tmpName);
      }
  }
  
  // Create and empty TreeView
  TreeView&lt;String&gt; duckTree = new TreeView&lt;String&gt;();
  
  // Create TreeItems for the Hierarchy of the TreeView
  CheckBoxTreeItem&lt;String&gt; root = new CheckBoxTreeItem&lt;String&gt;("Parent");
  CheckBoxTreeItem&lt;String&gt; lm1 = new CheckBoxTreeItem&lt;String&gt;("Child1");
  CheckBoxTreeItem&lt;String&gt; lm2 = new CheckBoxTreeItem&lt;String&gt;("Child2");
  
  for (String item : prefixMember) {
      CheckBoxTreeItem&lt;String&gt; treeItem = new CheckBoxTreeItem&lt;String&gt;(item.toString());
      for (String subItem : memberArray) {
          if (!subItem.isEmpty() &amp;&amp; subItem.substring(0, 3).equals(item)) {
              CheckBoxTreeItem&lt;String&gt; treeSubItem = new CheckBoxTreeItem&lt;String&gt;(
                          subItem.toString());
                      treeSubItems.add(treeSubItem);
          }
      }
      treeItems.add(treeItem);
      treeItem.getChildren().addAll(treeSubItems);
      treeSubItems.clear();
  }
  
  root.getChildren().addAll(treeItems);
  treeItems.clear();
  
  // Create a TreeView using the root TreeItem
  TreeView&lt;String&gt; royalTree = new TreeView&lt;String&gt;(root);
  royalTree.setCellFactory(CheckBoxTreeCell.&lt;String&gt;forTreeView());
  
  // Set a ChangeListener to handle events that occur with a Treeitem
  // is selected
  royalTree.getSelectionModel().selectedItemProperty()
          .addListener(new ChangeListener&lt;TreeItem&lt;String&gt;&gt;() {
              public void changed(
                      ObservableValue&lt;? extends TreeItem&lt;String&gt;&gt; observableValue,
                      TreeItem&lt;String&gt; oldItem, TreeItem&lt;String&gt; newItem) {
                  // Gets fired only on selection of tree item
                  // Need to get fired on selection of check box too
                  // Select the respective checkbox on selection of tree item
              }
          });
  
  hBox.getChildren().add(royalTree);
  groupRoot.getChildren().add(hBox);
  fxPanel.setScene(scene);
  </code></pre>