title: Remove node from TreeView
body: <p>I want to create this simple example of javaFX TreeView with context menu which can remove nodes from the tree:</p>
  
  <pre><code>public class TreeViewSample extends Application {
  
      private final Node rootIcon = new ImageView(
          new Image(getClass().getResourceAsStream("folder_16.png"))
      );
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
          primaryStage.setTitle("Tree View Sample");        
  
          TreeItem&lt;String&gt; rootItem = new TreeItem&lt;String&gt; ("Inbox", rootIcon);
          rootItem.setExpanded(true);
          for (int i = 1; i &lt; 6; i++) {
              TreeItem&lt;String&gt; item = new TreeItem&lt;String&gt; ("Message" + i);            
              rootItem.getChildren().add(item);
          }        
          TreeView&lt;String&gt; tree = new TreeView&lt;String&gt; (rootItem);        
          StackPane root = new StackPane();
          root.getChildren().add(tree);
          primaryStage.setScene(new Scene(root, 300, 250));
          primaryStage.show();
      }
  }
  </code></pre>
  
  <p>I tested this context menu to remove right click selected node:</p>
  
  <pre><code>final ContextMenu contextMenu = new ContextMenu();
          MenuItem item1 = new MenuItem("About");
          item1.setOnAction(new EventHandler&lt;ActionEvent&gt;()
          {
              @Override
              public void handle(ActionEvent e)
              {
                  System.out.println("About");
              }
          });
          MenuItem item2 = new MenuItem("Preferences");
          item2.setOnAction(new EventHandler&lt;ActionEvent&gt;()
          {
              @Override
              public void handle(ActionEvent e)
              {
                  System.out.println("Preferences");
              }
          });
          MenuItem item3 = new MenuItem("Remove");
          item3.setOnAction(new EventHandler&lt;ActionEvent&gt;()
          {
              @Override
              public void handle(ActionEvent e)
              {
  
                  DynamicTreeNodeModel c = treeView.getSelectionModel().getSelectedItem().getValue();
                  boolean remove = treeView.getSelectionModel().getSelectedItem().getChildren().remove(c);
                  System.out.println("Remove");
              }
          });
          contextMenu.getItems().addAll(item1, item2, item3);
  
          treeView.setContextMenu(contextMenu);
  </code></pre>
  
  <p>For some reason the code is not working. Can you help me to fix this issue?</p>