我有一个问题,如何将可扩展的 Threeview 插入 Accordion。
这是手风琴的代码:
public TitledPane createConnectionsTree(String title) {
connectionsData = FXCollections.observableArrayList(connectionsList);
ListView<ConnectionsObject> lv = new ListView<>(connectionsData);
lv.setCellFactory(new Callback<ListView<ConnectionsObject>, ListCell<ConnectionsObject>>() {
@Override
public ListCell<ConnectionsObject> call(ListView<ConnectionsObject> p) {
return new ConnectionsCellFactory();
}
});
AnchorPane content = new AnchorPane();
content.getChildren().add(lv);
// add to TitelPane
TitledPane pane = new TitledPane(title, content);
return pane;
}
这是树视图代码:
public void initTree() {
rootNode.setExpanded(true);
for (Employee employee : employees) {
TreeItem<String> empLeaf = new TreeItem<>(employee.getName());
boolean found = false;
for (TreeItem<String> depNode : rootNode.getChildren()) {
if (depNode.getValue().contentEquals(employee.getDepartment())) {
depNode.getChildren().add(empLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem depNode = new TreeItem(employee.getDepartment());
rootNode.getChildren().add(depNode);
depNode.getChildren().add(empLeaf);
}
}
VBox box = new VBox();
TreeView<String> treeView = new TreeView<>(rootNode);
treeView.setShowRoot(true);
treeView.setEditable(true);
box.getChildren().add(treeView);
}
附言
我得到这个结果:
我想在展开树视图时展开手风琴的滑块而不是树视图的滑块。这是我测试的代码:
public TitledPane createConnectionsList(String title) {
rootNode.setExpanded(true);
for (ThreeData conn : connectionsThree) {
TreeItem<String> empLeaf = new TreeItem<>(conn.getName());
boolean found = false;
for (TreeItem<String> depNode : rootNode.getChildren()) {
if (depNode.getValue().contentEquals(conn.getDepartment())) {
depNode.getChildren().add(empLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem depNode = new TreeItem(conn.getDepartment());
rootNode.getChildren().add(depNode);
depNode.getChildren().add(empLeaf);
}
}
TreeView<String> treeView = new TreeView<>(rootNode);
treeView.setShowRoot(true);
treeView.setEditable(true);
AnchorPane content = new AnchorPane();
// Set aligment - fill the accordion with the three content
AnchorPane.setLeftAnchor(treeView, 0d);
AnchorPane.setRightAnchor(treeView, 0d);
AnchorPane.setBottomAnchor(treeView, 0d);
AnchorPane.setTopAnchor(treeView, 0d);
content.getChildren().add(treeView);
// Add to TitelPane
TitledPane pane = new TitledPane(title, content);
return pane;
}