gpt4 book ai didi

JavaFX : FXML: How to make the child to extend its size to fit the parent pane?

转载 作者:IT老高 更新时间:2023-10-28 20:48:48 25 4
gpt4 key购买 nike

我设法在父 fxml(mainMenu UI)下加载了一个子 fxml(子 UI)。我创建了一个 ID 为“mainContent”的 AnchorPane。此 Pane 绑定(bind)到 4 个面,并根据舞台变化。

子窗口将被加载到“mainContent” anchor Pane 中。但是,我无法弄清楚如何让 child 与它的 parent “mainContent”一起改变。

我的子 UI 是这样调用的。

@FXML
private void mnuUserLevel_onClick(ActionEvent event) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("DBedit.fxml"));
loader.setController(new DBeditEntityUserlevel());

try {
Node n = (Node)loader.load();
mainContent.getChildren().add(n);
} catch (IOException e){
System.out.println(e.getMessage());
}
}

为了进一步说明我的问题,请查看我的快照。红色方 block 是 child 。黄色方 block 是 MainMenu 父级的“mainContent”AnchorPane。

enter image description here

最佳答案

如果你设置 static 方法 setTopAnchor(child, value), setBottomAnchor( ... ), setLeftAnchor( . ..), setRightAnchor( ... )AnchorPane0.0,子 Node 将被拉伸(stretch)到父 AnchorPane 的完整范围。

文档链接:AnchorPane

编辑:在文档链接中,您还可以查看如何在 java 代码中设置这些值。

FXML 示例:

<AnchorPane fx:id="mainContent" ...>
<StackPane fx:id="subPane" AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" ></StackPane>
</AnchorPane>

关于JavaFX : FXML: How to make the child to extend its size to fit the parent pane?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22270994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com