我有这棵树,它会生成带有数据的小树。
public TitledPane createConnectionsList(String title) {
TreeItem<String> rootNode = new TreeItem<>("Connection 1", null);
rootNode.setExpanded(true);
for (ConnectionData data : connectionDataList) {
TreeItem<String> connLeaf = new TreeItem<>(data.getDBGWName());
boolean found = false;
for (TreeItem<String> depNode : rootNode.getChildren()) {
if (depNode.getValue().contentEquals(data.getTableName())) {
depNode.getChildren().add(connLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem<String> depNode = new TreeItem<>(data.getTableName(), null);
rootNode.getChildren().add(depNode);
depNode.getChildren().add(connLeaf);
}
}
VBox box = new VBox();
final Scene scene = new Scene(box, 700, 600);
scene.setFill(Color.LIGHTGRAY);
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;
}
public List<ConnectionData> connectionDataList;
public static class ConnectionData {
private String DBGWName;
private String TableName;
public ConnectionData(String DBGWName, String TableName) {
this.DBGWName = DBGWName;
this.TableName = TableName;
}
public String getDBGWName() {
return DBGWName;
}
public void setDBGWName(String DBGWName) {
this.DBGWName = DBGWName;
}
public String getTableName() {
return TableName;
}
public void setTableName(String TableName) {
this.TableName = TableName;
}
}
connectionDataList = Arrays.<ConnectionData>asList(
new ConnectionData("Table 1", "DBGW1"),
new ConnectionData("Table 2", "DBGW1"),
new ConnectionData("Table 3", "DBGW1"),
new ConnectionData("Table 4", "DBGW1"),
new ConnectionData("Table 5", "DBGW1"),
new ConnectionData("Table 6", "DBGW2"),
new ConnectionData("Table 7", "DBGW2"),
new ConnectionData("Table 8", "DBGW2"),
new ConnectionData("Table 9", "DBGW2"),
new ConnectionData("Table 10", "DBGW2"),
new ConnectionData("Table 11", "DBGW2"),
new ConnectionData("Table 12", "DBGW3"));
我想当我点击主节点Connection 1
打开一个对话框。当我点击一个DBGW1
子节点打开一个新的对话框窗口,当我点击一个子节点Table
打开 3td 简单对话框时,我也想要。为了调用 Java 方法或刷新主阶段,我必须在哪里以及如何放置事件侦听器。