如何在所有场景 JavaFX FXML 中包含公共边栏或 Header

How to Include Common Sidebar or Header in All Scenes JavaFX FXML

我正在学习 JavaFX 并面临在所有场景中共享相同资源的问题。

如 PHP 中的示例,我们可以包括像 include("header.php");include("sidebar.php");

这样的公共页面

但是如何在 JavaFX 中的所有 scenes/stages 上添加相同的边栏?

使用<fx:include>:

<BorderPane>
    <top>
        <fx:include source="header.fxml"/>
    </top>
    <left>
        <fx:include source="sidebar.fxml"/>
    </left>
    <center>
        <!-- ... -->
    </center>
</BorderPane>