title: How to get all selected tree items in a tree view in JavaFX
body: <p>I need to be able to get an updated list of all selected items in a tree view (which has multiple selection on).</p>
  
  <p>This example: <a href="https://stackoverflow.com/questions/13857041/tree-item-select-event-in-javafx2">Tree item select event in javafx2</a></p>
  
  <p>shows how to respond/identify one selected item at a time. Is there a way to get all selected items at once? Something like the hypothetical non-working code below:</p>
  
  <pre><code>ArrayList&lt;TreeItem&gt; selectedTreeItems = new ArrayList&lt;&gt;();
  
  myTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
          @Override
          public void changed(ObservableValue observable, Object oldValue, Object newValue) {
              selectedTreeItems.clear();//reset the list. correct?
  
              //get a new list of children of the root
              ObservableList objects = myTreeView.getRoot().getChildren();
  
              //loop to get the selected items.
              for (int i = 0; i &lt; objects.size(); i++) {
                  TreeItem object = (TreeItem) objects.get(i);
                  if (thisObjectIsSelected(object)) {
                      selectedTreeItems.add(object);
                  }
              }
  
  
          }
      });
  
      privatevoid thisObjectIsSelected(TreeItem item){
      //what do I do here?
      }
  </code></pre>
  
  <p>I am not sure how to achieve what I want. Any help is greatly appreciated!</p>