javafx Define Blocks and


Sometimes a element needs to be created outside of the usual object structure in the fxml.

This is where Define Blocks come into play:

Contents inside a <fx:define> element are not added to the object created for the parent element.

Every child element of the <fx:define> needs a fx:id attribute.

Objects created this way can be later referenced using the <fx:reference> element or by using expression binding.

The <fx:reference> element can be used to reference any element with a fx:id attribute that is handled before the <fx:reference> element is handled by using the same value as the fx:id attribute of the referenced element in the source attribute of the <fx:reference> element.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox xmlns:fx="" prefHeight="300.0" prefWidth="300.0" xmlns="">
            <String fx:value="My radio group" fx:id="text" />
                <!-- reference text defined above using fx:reference -->
                <fx:reference source="text"/>
        <RadioButton text="Radio 1">
                <ToggleGroup fx:id="group" />
        <RadioButton text="Radio 2">
                <!-- reference ToggleGroup created for last RadioButton -->
                <fx:reference source="group"/>
        <RadioButton text="Radio 3" toggleGroup="$group" />
        <!-- reference text defined above using expression binding -->
        <Text text="$text" />