如何将子类作为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的错误 - &gt; ObservableList&gt;类型中的方法setAll(TreeItem ...)不适用于参数(TreeItem&gt;)
这应该是什么样的:
firstColumn
.setCellValueFactory((CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(
p.getValue().getValue()));