使用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>发布于 2020-01-22 00:15:19
有两种方法可以做到:
将其添加到java中
加载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));FXML内部
正如@Sedrick在评论中指出的那样,您还可以使用fx:include
<center>
<fx:include source="center.fxml"/>
</center>在这两个选项中,它与top、bottom、left和right的工作方式相同。
https://stackoverflow.com/questions/59844744
复制相似问题