0

How can i add children as ArrayList to root and set setCellValueFactory in JavaFx . I want to show second item as text for each node, and use the first one for other computation. the ArrayList has the size of 2 for each node.

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("IT");
    Scene scene = new Scene(new Group(), 1200, 1000);
    Group sceneRoot = (Group) scene.getRoot();
    final TreeItem<String> root = new TreeItem<>("Root Node");


TreeItem<ArrayList<String>> noChild = null;
    Set<String> remainingKeysAll = new HashSet<>(dc.getFuncAll().keySet());

    remainingKeysAll.removeAll(dc.getCombiFunc().keySet());
    for (List<String> values : dc.getCombiFunc().values()) {
        remainingKeysAll.removeAll(values);
    }
    for (String valueRemained : remainingKeysAll) {
        ArrayList<String> tempNameId = new ArrayList<>();
        tempNameId.add(valueRemained);// function key from all
        tempNameId.add(dc.getFuncAll().get(valueRemained).get(1));
        //tempNameId has here 9 item in it
        noChild = new TreeItem<>(tempNameId);

    }
    root.getChildren().setAll(noChild); 
    System.out.println(noChild); // gives TreeItem [ value: [AUF_1087400004054_10476, Patientenabrechnung (stationär)] ] but (There should be 8 other lists.)

Error from root.getChildren -> The method setAll(TreeItem...) in the type ObservableList> is not applicable for the arguments (TreeItem>)

and how should this look like:

firstColumn
            .setCellValueFactory((CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(
                    p.getValue().getValue()));
Iman
  • 769
  • 1
  • 13
  • 51
  • All the `TreeItem`s in your tree need to be the same type (and need to be the same type as the `TreeView`). So this simply won't compile, because the `root` is a `TreeItem` and the child node you are trying to add is a `TreeItem>`. The rest of your code is pretty unclear to me; I don't really understand how your data structures are supposed to work. Also, you repeatedly reassign the value of `noChild` in a loop, but then only use the last value. Is that intentional (and if so, why)? – James_D Feb 28 '15 at 18:11
  • In tempNameId there are 9 items which i want to add them all as treeitem. I need to deal with two types of information for each treeitem and column name. they have each a name which user can see and i need to save a unique key for each treeitem and column name to do some comparation and fill the cells. I have some information as treemaps and want to show them in treetable. i have to compare for example all keys for all treeitems with values of another treemap and again compare other value of that one with keys of columns and if there is match i want to write a value to related cell. – Iman Feb 28 '15 at 19:34

0 Answers0