title: filling TreeTableView in fxml dynamicly from JavaFX
body: <p>I want to fill a TreeTableView dynamically. I have created the view with Scenebuilder. In MyController I have a Draw button which by cliking calls a method, which makes a treetable. I have references set. when i click  the button only columns are appear. The first column which is ought to show the treecolumn shows nothing and there is also no other value under columns. The TreeTableView works when I just use it alone and add it to scene, but now i want to use the values to fill the treeTable which is made by scene Builder. There is something else that i can not figure out. The columns are set correctly when comment out <code>treeTable = new TreeTableView&lt;&gt;(root);</code> which is under treeTable comment! otherwise the columns are not shown either.<br>
  That is what i want to see:
  <img src="https://i.stack.imgur.com/6oQ5G.png" alt="result that i want to see">
  <img src="https://i.stack.imgur.com/rcvPi.png" alt="that is what i see after trying to inject values in fxml treetable"></p>
  
  <pre><code>package controller;
  
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.List;
  import java.util.ResourceBundle;
  import java.util.Set;
  import java.util.TreeMap;
  import java.util.Map.Entry;
  import java.util.stream.Collectors;
  
  import model.DataConstructor;
  import javafx.beans.property.ReadOnlyObjectWrapper;
  import javafx.beans.property.ReadOnlyStringWrapper;
  import javafx.beans.value.ObservableValue;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  
  import javafx.scene.control.Label;
  import javafx.scene.control.Tooltip;
  import javafx.scene.control.TreeItem;
  import javafx.scene.control.TreeTableCell;
  import javafx.scene.control.TreeTableColumn;
  import javafx.scene.control.TreeTableView;
  import javafx.scene.control.TreeTableColumn.CellDataFeatures;
  import javafx.util.Callback;
  
  public class MainController implements Initializable {
  
  
  
  private TreeItem&lt;String&gt; root = new TreeItem&lt;&gt;("Functions");
  private DataConstructor dc = new DataConstructor();
  
  @FXML
  private TreeTableView&lt;String&gt; treeTable;
  
  @Override
  public void initialize(URL location, ResourceBundle resources) {
      // TODO Auto-generated method stub
  
  }
  
  public void testDraw(ActionEvent event) {
  
      drawTable();
  }
  
  private void drawTable() {
  
      root.setExpanded(true);
      Set&lt;String&gt; combinedKeys = new HashSet&lt;&gt;(dc.getCombiFunc().keySet());
      Set&lt;String&gt; funcAllKeys = new HashSet&lt;&gt;(dc.getSortedfuncAll().keySet());
      funcAllKeys.removeAll(dc.getCombiFunc().keySet());
      for (List&lt;String&gt; value : dc.getCombiFunc().values()) {
          funcAllKeys.removeAll(value);
      }
      for (String valueremained : funcAllKeys) {
          ArrayList&lt;String&gt; tempNameId = new ArrayList&lt;&gt;();
          tempNameId.add(dc.getSortedfuncAll().get(valueremained));
          // all elements which are not in combined functions (They are all
          // orphan)
          root.getChildren().add(new TreeItem&lt;String&gt;(tempNameId.get(0)));
      }
      Set&lt;String&gt; keyFromcombined = new HashSet&lt;&gt;();
      List&lt;String&gt; valueOfCombined = new ArrayList&lt;String&gt;();
      for (Entry&lt;String, List&lt;String&gt;&gt; ent : dc.getCombiFunc().entrySet()) {
          valueOfCombined.add(ent.getValue().get(0));
      }
      List&lt;String&gt; rootKeyList = new ArrayList&lt;&gt;();
      for (String key : combinedKeys) {
  
          if (!valueOfCombined.contains((key))) {
  
              keyFromcombined.add(dc.getFuncAll().get(key));
              rootKeyList.add(key);
          }
      }
      String[] rootKeys = rootKeyList.toArray(new String[rootKeyList.size()]);
  
      // ////////////////treetable////////////////////////////
  
      treeTable = new TreeTableView&lt;&gt;(root);
  
      Arrays.stream(rootKeys).forEach(
              rootKey -&gt; root.getChildren().add(
                      createTreeItem(dc.getCombiFunc(), rootKey)));
  
      // ////////////////First column/////////////////////////
  
      TreeTableColumn&lt;String, String&gt; firstColumn = new TreeTableColumn&lt;&gt;("");
      treeTable.getColumns().add(firstColumn);// Tree column
      firstColumn
              .setCellValueFactory(new Callback&lt;CellDataFeatures&lt;String, String&gt;, ObservableValue&lt;String&gt;&gt;() {
                  public ObservableValue&lt;String&gt; call(
                          CellDataFeatures&lt;String, String&gt; p) {
                      return new ReadOnlyStringWrapper(p.getValue()
                              .getValue());
                  }
              });
  
      // //////////////////Rest Columns////////////////////////
  
      for (Entry&lt;String, String&gt; ent : dc.getSortedAssignedOrg().entrySet()) {
  
          TreeTableColumn&lt;String, ArrayList&lt;String&gt;&gt; col = new TreeTableColumn&lt;&gt;();
          Label label = new Label(ent.getValue());
          col.setGraphic(label);
          label.setTooltip(new Tooltip(label.getText()));// tooltip for column
                                                          // headers
          col.setPrefWidth(45);
          //cell Value Factory////////////////////////
          col.setCellValueFactory(new Callback&lt;TreeTableColumn.CellDataFeatures&lt;String, ArrayList&lt;String&gt;&gt;, ObservableValue&lt;ArrayList&lt;String&gt;&gt;&gt;() {
              @Override
              public ObservableValue&lt;ArrayList&lt;String&gt;&gt; call(
                      CellDataFeatures&lt;String, ArrayList&lt;String&gt;&gt; param) {
                  TreeMap&lt;String, List&lt;String&gt;&gt; temp = (TreeMap&lt;String, List&lt;String&gt;&gt;) dc
                          .getFuncTypeOrg().clone();
                  ArrayList&lt;String&gt; result = new ArrayList&lt;&gt;();
                  for (int i = 0; i &lt; dc.getFuncTypeOrg().size(); i++) {
                      List&lt;String&gt; list = temp.firstEntry().getValue();
                      String key = temp.firstEntry().getKey();
                      // root.getChildren();
                      if (list.get(1).equals(param.getValue().getValue())
                              &amp;&amp; list.get(5).equals(label.getText())) {
                          result.add(0, list.get(2));// weight
                          // //////////////org combi TODO
                          for (Entry&lt;String, Set&lt;String&gt;&gt; ent : dc
                                  .getCombiOrg().entrySet()) {
                              if (ent.getKey().contains(col.getText()))
                                  for (Set&lt;String&gt; value : dc.getCombiOrg()
                                          .values()) {
                                      if (value.contains(col.getText()))
                                          System.out.println(col.getText());
                                  }
                          }
                          // ///////////////org combi
                          if (list.size() &gt; 6) {
                              result.add(1, list.get(list.size() - 1));// color
                              result.add(2, list.get(6));// App component
                          }
  
                          else
                              result.add("white");
                          result.add("noOrg");
  
                      } else {
                          temp.remove(key);
                      }
  
                  }
  
                  return new ReadOnlyObjectWrapper&lt;ArrayList&lt;String&gt;&gt;(result);
              }
          });
  
          // //////////////cellfactory/////////////////////////
          col.setCellFactory(new Callback&lt;TreeTableColumn&lt;String, ArrayList&lt;String&gt;&gt;, TreeTableCell&lt;String, ArrayList&lt;String&gt;&gt;&gt;() {
              @Override
              public TreeTableCell&lt;String, ArrayList&lt;String&gt;&gt; call(
                      TreeTableColumn&lt;String, ArrayList&lt;String&gt;&gt; param) {
                  return new TreeTableCell&lt;String, ArrayList&lt;String&gt;&gt;() {
                      public void updateItem(ArrayList&lt;String&gt; item,
                              boolean empty) {
                          super.updateItem(item, empty);
  
                          if (item == null || empty) {
                              setStyle("");
                              setText("");
                          } else if (item.contains("Green")) {
                              float weightInt = Float.parseFloat(item.get(0));
                              float res = weightInt * 1;
                              String resString = Float.toString(res);
                              this.setStyle("-fx-background-color:green");
                              setTooltip(new Tooltip(item.get(2)));
                              setText(resString);
                          } else if (item.contains("yellow")) {
                              this.setStyle("-fx-background-color:yellow");
                              setTooltip(new Tooltip(item.get(2)));
                              setText("0");
                          } else if (item.contains("white")) {
                              setText("DD");
                          }
                      }
                  };
              };
  
          });
  
          treeTable.getColumns().add(col);
      }
      // end for col
  
  
  treeTable.setPrefWidth(1200);
  treeTable.setPrefHeight(500);
      treeTable.setShowRoot(false);
      treeTable.setTableMenuButtonVisible(true);
  }
  
  /**
   * Create a TreeItem for a TreeView from a set of data given the data and an
   * identified root within the data.
   */
  private TreeItem&lt;String&gt; createTreeItem(TreeMap&lt;String, List&lt;String&gt;&gt; data,
          String rootKey) {
      TreeItem&lt;String&gt; item = new TreeItem&lt;&gt;();
      item.setValue(rootKey);
      item.setExpanded(true);
  
      List&lt;String&gt; childData = data.get(rootKey);
      if (childData != null) {
          childData.stream().map(child -&gt; createTreeItem(data, child))
                  .collect(Collectors.toCollection(item::getChildren));
      }
  
      String valueName = item.getValue();
      //String sorteV = dc.getSortedfuncAll().get(valueName);
      item.setValue((dc.getSortedfuncAll().get(valueName)));
      return item;
  }
  </code></pre>
  
  <p>}</p>