JavaFX 如何锚定嵌套的 FXML 组件以匹配 parent 维度
JavaFX how to anchor nested FXML component to match parent dimensions
我正在创建一个使用嵌套 FXML 节点的应用程序。它们使用
等结构连接到 parent 控制器中的 parent 个节点
@FXML
private AnchorPane nestedNodeConnector;
,我附加了 child,如下所示:
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
nestedNodeConnector.getChildren().setAll((AnchorPane)child);
代码有点简化,但我希望自己解释得足够清楚。现在我的问题是我正在尝试加载(作为 child 节点)一个 as-large-as-possible AnchorPane,里面有一个锚定的 TableView。但是我无法让它工作,因为 TableView 维度永远不会粘在 parent 节点上(为了随着 window 大小增长)。
我能够在不嵌套 child 的情况下让它工作,但我真的必须在单独的 FXML 文件中加载 TableView。有什么建议么?我认为我的方法在 AnchorPane "nestedNodeConnector" 中创建了一个 AnchorPane "child",这弄乱了锚属性。
我所要做的就是锚定子 AnchorPane(到父 AnchorPane):
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
AnchorPane.setTopAnchor(child, 10.0);
AnchorPane.setBottomAnchor(child, 10.0);
AnchorPane.setLeftAnchor(child, 10.0);
AnchorPane.setRightAnchor(child, 10.0);
nestedNodeConnector.getChildren().setAll((AnchorPane)child);
我正在创建一个使用嵌套 FXML 节点的应用程序。它们使用
等结构连接到 parent 控制器中的 parent 个节点@FXML
private AnchorPane nestedNodeConnector;
,我附加了 child,如下所示:
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
nestedNodeConnector.getChildren().setAll((AnchorPane)child);
代码有点简化,但我希望自己解释得足够清楚。现在我的问题是我正在尝试加载(作为 child 节点)一个 as-large-as-possible AnchorPane,里面有一个锚定的 TableView。但是我无法让它工作,因为 TableView 维度永远不会粘在 parent 节点上(为了随着 window 大小增长)。
我能够在不嵌套 child 的情况下让它工作,但我真的必须在单独的 FXML 文件中加载 TableView。有什么建议么?我认为我的方法在 AnchorPane "nestedNodeConnector" 中创建了一个 AnchorPane "child",这弄乱了锚属性。
我所要做的就是锚定子 AnchorPane(到父 AnchorPane):
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
AnchorPane.setTopAnchor(child, 10.0);
AnchorPane.setBottomAnchor(child, 10.0);
AnchorPane.setLeftAnchor(child, 10.0);
AnchorPane.setRightAnchor(child, 10.0);
nestedNodeConnector.getChildren().setAll((AnchorPane)child);