Using FXML defines

To structure your FXML better, you can use fx:define to separate usage and declaration of various elements. For example, the preceding examples with includes can be rewritten by defining the include first and using it later through the $ prefix. Refer to the following code snippet:

<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<HBox xmlns:fx="http://javafx.com/fxml" fx:controller="chapter4.includes.FirstController">
<fx:define>
<fx:include fx:id="myLabel" source="MyLabel.fxml"/>
</fx:define>
<children>
<StackPane children="$myLabel">
</children>
</HBox>

Another common use case for define is setting a toggle group for radio buttons:

<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<HBox xmlns:fx="http://javafx.com/fxml" >
<fx:define>
<ToggleGroup fx:id="toggleGroup"/>
</fx:define>
<children>
<RadioButton text="radio1" toggleGroup="$toggleGroup"/>
<RadioButton text="radio2" toggleGroup="$toggleGroup"/>
<RadioButton text="radio3" toggleGroup="$toggleGroup"/>
</children>
</HBox>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.15.161