JavaFX:FXML:如何让孩子扩展其大小以适应父窗格? [英] JavaFX: FXML: How to make the child to extend its size to fit the parent pane?

查看:309
本文介绍了JavaFX:FXML:如何让孩子扩展其大小以适应父窗格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已设法在父fxml(mainMenu UI)下加载子fxml(子UI)。
我创建了一个id为mainContent的AnchorPane。此窗格绑定到4个方面,并且更改符合舞台。

I have managed to load a child fxml(sub UI) under a parent fxml (mainMenu UI). I have created an AnchorPane with id "mainContent". This pane is bound to 4 sides and changes in accords to the stage.

子窗口将被加载到mainContent锚定窗格中。但是,我无法弄清楚如何让孩子与其父mainContent一起改变。

The child window will be loaded into the "mainContent" anchorpane. However, I can't figure out how to make the child to change along with its parent "mainContent".

我的子UI就是这样调用的。

My child UI is called like this.

@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());
    }
}

为了进一步说明我的问题,请参阅我的快照。红场是孩子。黄色方块是MainMenu父级的mainContentAnchorPane。

To further illustrate my question, please see my snap shot. The red square is the child. The yellow square is the "mainContent" AnchorPane of the MainMenu parent.

推荐答案

如果设置 topAnchor,bottomAnchor,leftAnchor,rightAnchor AnchorPane内的窗格值 0.0 面板将被拉伸到周围AnchorPane的完整范围。

If you set the topAnchor, bottomAnchor, leftAnchor, rightAnchor values of the pane inside your AnchorPane to 0.0 the panel will get stretched to the full extend of the surrounding AnchorPane.

文档链接: AnchorPane

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

edit: in the documentation link you can also see how you can set these values in your java code.

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:如何让孩子扩展其大小以适应父窗格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆