[英]JavaFX building borderPane with FXML files
Using a BorderPane
layout, can you populate each part of it (top, left, center, right and bottom) using separate FXML files?使用
BorderPane
布局,您能否使用单独的 FXML 文件填充它的每个部分(顶部、左侧、中间、右侧和底部)?
So I would have a main.fxml like:所以我会有一个 main.fxml 像:
<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>
There are 2 ways to do it:有两种方法可以做到:
After you load the BorderPane
, you can load other FXML files and put them into the BorderPane
.加载
BorderPane
,您可以加载其他 FXML 文件并将它们放入BorderPane
。
Eg例如
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));
As @ Sedrick points out in the comments, you can also use fx:include :正如@ Sedrick在评论中指出的,您还可以使用fx:include :
<center>
<fx:include source="center.fxml"/>
</center>
In both options, it works the same with top
, bottom
, left
and right
.在这两个选项中,它的作用与
top
、 bottom
、 left
和right
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.