首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JavaFX使用FXML文件构建borderPane

JavaFX使用FXML文件构建borderPane
EN

Stack Overflow用户
提问于 2020-01-21 23:53:13
回答 1查看 493关注 0票数 1

使用BorderPane布局,您可以使用单独的FXML文件填充布局的每个部分(顶部、左侧、中间、右侧和底部)吗?

所以我会有一个这样的main.fxml:

代码语言:javascript
复制
<BorderPane fx:controller="main.mainController"  xmlns:fx="http://javafx.com/fxml" >

    <top>
        reads from top.fxml
    </top>

    <left>
        reads from left.fxml
    </left>

    <center>
        reads from center.fxml
    </center>

    <right>
        reads from right.fxml
    </right>

    <bottom>
        reads from bottom.fxml
    </bottom>

</BorderPane>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-22 00:15:19

有两种方法可以做到:

将其添加到java中

加载BorderPane之后,可以加载其他FXML文件并将它们放入BorderPane中。

例如。

代码语言:javascript
复制
BorderPane root=FXMLLoader.load(this.getClass().getResource("root.fxml");//maybe this.getClass().getClassLoader().getResource("root.fxml"), depending on project structure
AnchorPane center=FXMLLoader.load(this.getClass().getResource("center.fxml");//maybe this.getClass().getClassLoader().getResource("center.fxml"), depending on project structure
root.setCenter(center);
stage.setScene(new Scene(root));

FXML内部

正如@Sedrick在评论中指出的那样,您还可以使用fx:include

代码语言:javascript
复制
<center>
    <fx:include source="center.fxml"/>
</center>

在这两个选项中,它与topbottomleftright的工作方式相同。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59844744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档