[英]JavaFX building borderPane with FXML files
使用BorderPane
布局,您能否使用单独的 FXML 文件填充它的每个部分(顶部、左侧、中间、右侧和底部)?
所以我会有一个 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>
有两种方法可以做到:
加载BorderPane
,您可以加载其他 FXML 文件并将它们放入BorderPane
。
例如
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));
正如@ Sedrick在评论中指出的,您还可以使用fx:include :
<center>
<fx:include source="center.fxml"/>
</center>
在这两个选项中,它的作用与top
、 bottom
、 left
和right
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.