Java Reference
In-Depth Information
Listing 3-17. ResourceAndBindingExample.properties
location=Location:
resources=Resources:
currentDate=CurrentDate:
Listing 3-18. ResolutionAndBindingExample_fr_FR.properties
location=Emplacement:
resources=Resources:
currentDate=Date du jour:
Listing 3-19. ResolutionAndBindingExample.css
#vbox {
-fx-background-color: azure ;
}
Location resolution is used in the FXML file to specify the location of the CSS file. The stylesheet attribute is set
to the location “ @ResolutionAndBindingExample.css ”:
<VBox id="vbox" alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="200.0" prefWidth="700.0" spacing="10.0"
stylesheets="@ResolutionAndBindingExample.css" xmlns=" http://javafx.com/javafx/8 "
xmlns:fx=" http://javafx.com/fxml/1 " fx:controller="ResolutionAndBindingController">
The stylesheet sets the background color of the VBox to azure. Resource resolution is used to set the text for three
labels in the program:
<Label text="%location">
<Label text="%resources">
<Label text="%currentDate">
These labels will get their texts from the resource bundle that is supplied to the FXMLLoader before the FXML
file is loaded. Both the default locale and a French locale translation of the properties file are provided. Variable
resolution happens between a defined java.util.Date instance and a Label :
<fx:define>
<Date fx:id="capturedDate"/>
</fx:define>
<Label fx:id="currentDateLabel" text="$capturedDate"/>
The defined Date was given the fx:id of capturedDate and the label used the variable for its text. Finally, the
expression binding happens between a TextField and a Label :
<TextField fx:id="textField"/>
<Label text="${textField.text}"/>
The TextField was given the fx:id of textField and the label binds to the expression textField.text , with a
result of the label mimicking what is typed in the text field. When the ResolutionAndBindingExample is run with the
French locale, the Resolution and Binding Example window shown in Figure 3-6 is displayed.
Search WWH ::




Custom Search