1 Reply Latest reply: Dec 8, 2012 3:38 AM by MiPa RSS

    Data Populating on clicking a tree item

    abhinay_a
      I have a tree as

      TreeItem<String> itemClient = new TreeItem<String> ("Client");
      itemClient.setExpanded(false);

      TreeItem<String> itemClient1 = new TreeItem<String> ("Place Order");
      itemClient.getChildren().add(itemClient1);
      TreeItem<String> itemClient2 = new TreeItem<String> ("Edit Order");
      itemClient.getChildren().add(itemClient2);
      TreeItem<String> itemClient3 = new TreeItem<String> ("Cancel Order");
      itemClient.getChildren().add(itemClient3);

      final TreeItem<String> itemVendor = new TreeItem<String> ("Vendor");
      itemVendor.setExpanded(false);

      final TreeItem<String> itemVendor1 = new TreeItem<String> ("Place Order");
      itemVendor.getChildren().add(itemVendor1);
      TreeItem<String> itemVendor2 = new TreeItem<String> ("Edit Order");
      itemVendor.getChildren().add(itemVendor2);
      TreeItem<String> itemVendor3 = new TreeItem<String> ("Cancel Order");
      itemVendor.getChildren().add(itemVendor3);


      TreeItem<String> rootNode = new TreeItem<String>("");
      rootNode.getChildren().addAll(itemClient, itemVendor);


      TreeView<String> tree = new TreeView<String> (rootNode);
      tree.setShowRoot(false);

      vbox.getChildren().addAll(tree);
      tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);


      This tree is placed on the left of the border pane.I want to populate something at the center when on of this is clicked.

      I have different data for each of the tree items.
      Any idea on how to achieve this ?
        • 1. Re: Data Populating on clicking a tree item
          MiPa
          Just add a listerner to the selection model.
          tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
             @Override
             public void changed(ObservableValue<? extends TreeItem<String>> observable, TreeItem<String> oldValue, TreeItem<String> newValue) {
                System.out.println("Selection: " + newValue);
                // Add your stuff here
             }
          });
          Michael