Using static methods in FXML

Some JavaFX APIs require the use of static methods, like those we used to adjust BorderPane in Chapter 1, Stages, Scenes, and Layout:

BorderPane.setAlignment(label, Pos.CENTER);

To use them in FXML, you need to call them backward—inside a parameter to be adjusted, you need to assign a value to the class name and property name combination—BorderPane.alignment="CENTER".

Here is a full example of such FXML (note another example of using define, adding it to make an image look better):

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>

<BorderPane padding="$insets" xmlns:fx="http://javafx.com/fxml/1">
<fx:define>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" fx:id="insets"/>
</fx:define>
<top>
<Label text="Label" BorderPane.alignment="CENTER"/>
</top>
<bottom>
<TextField fx:id="textField" />
</bottom>
</BorderPane>

On running the preceding code, you'll see the following output:

..................Content has been hidden....................

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