我正在寻找一种解决方案,如何TreeView
从ArrayList
. 我有这个ArrayList
女巫包含连接名称、数据库服务器名称和表列表:
public List<ConnectionsListObj> connListObj = new ArrayList<>();
public class ConnectionsListObj {
private String connectionName;
private String dbgwName;
private String tableName;
public ConnectionsListObj(String connectionName, String dbgwName, String tableName) {
this.connectionName = connectionName;
this.dbgwName = dbgwName;
this.tableName = tableName;
}
public String getConnectionName() {
return connectionName;
}
public void setConnectionName(String connectionName) {
this.connectionName = connectionName;
}
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;
}
}
我需要某种循环来查看树并使用以下代码生成树:
TreeItem<String> treeItemConnections = new TreeItem<> ("Connections");
TreeItem<String> nodeItemDBGW = new TreeItem<>("DBGW 1");
treeItemConnections.getChildren().add(nodeItemDBGW);
TreeItem<String> nodeItemTable = new TreeItem<>("Table 1");
nodeItemDBGW.getChildren().add(nodeItemTable);
TreeView<String> treeView = new TreeView<>(treeItemConnections);
StackPane root = new StackPane();
root.getChildren().add(treeView);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("java-buddy.blogspot.com");
primaryStage.setScene(scene);
primaryStage.show();
问题是我如何制作一个循环来查看ArrayList
并构造三个?而且,当我在节点上选择时,我想获取节点的类型。