0

如何将子项作为 ArrayList 添加到 root 并在 JavaFx 中设置 setCellValueFactory 。我想将第二项显示为每个节点的文本,并将第一项用于其他计算。ArrayList 每个节点的大小为 2。

@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.)

来自 root.getChildren 的错误 -> ObservableList> 类型中的方法 setAll(TreeItem...) 不适用于参数 (TreeItem>)

这应该是怎样的:

firstColumn
            .setCellValueFactory((CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(
                    p.getValue().getValue()));
4

0 回答 0