I've started a new JavaFX 2 project and I've built the main Stage with SceneBuilder. How can I design a new, separate Pane (i.e. a new FXML file with its own controller class) and add it to the main scene?

有帮助吗?

解决方案

Static Inclusion

fx:include can be placed in the parent FXML file to statically include a child FXML with it's own Controller.

For example (from the Oracle FXML Introduction), given the following markup:

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox xmlns:fx="http://javafx.com/fxml">
    <children>
        <fx:include source="my_button.fxml"/>
    </children>
</VBox>

If my_button.fxml contains the following:

<?import javafx.scene.control.*?>
<Button text="My Button"/>

the resulting scene graph would contain a VBox as a root object with a single Button as a child node.

Dynamic Loading

Loading new fxml in the same scene describes how to load the new FXML files dynamically into a replaceable child Pane.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top