Java Reference
In-Depth Information
The
price
field illustrates a way to construct a
Double
object. The
fx:value
attribute invokes the
valueOf(String)
method on
Double
. This works on any Java class that has a factory method
valueOf(String)
:
<price>
<Double fx:value="3.1415926"/>
</price>
The
discount
field illustrates how to use a constant defined in a Java class. The
fx:constant
attribute accesses
constant (public static final) fields of the type of its element. The following sets the discount field to
Utilities.TEN_PCT
,
which is
0.1
:
<discount>
<Utilities fx:constant="TEN_PCT"/>
</discount>
The
sizes
field illustrates the use of factory methods to create objects. The
fx:factory
attribute invokes the
specified factory method on the type of its element. In our case, it calls
Utilities.createList()
to create a list of
Integer
s, which is then populated with three
Integer
s. Notice that
sizes
is a read-write property. You will see an
example of how a read-only list property is populated later.
<sizes>
<Utilities fx:factory="createList">
<Integer fx:value="1"/>
<Integer fx:value="2"/>
<Integer fx:value="3"/>
</Utilities>
</sizes>
The
profits
field illustrates how to populate a read-write map. Here we set the profits field to a
HashMap
that we
create with key/value pairs:
<profits>
<HashMap q1="1000" q2="1100" q3="1200" a4="1300"/>
</profits>
The
inventory
field illustrates how to define an object in one place and reference it in another place. The
fx:define
element creates a stand-alone object that has an
fx:id
attribute. The
fx:reference
element creates a
reference to an object defined elsewhere, and its
source
attribute points to the
fx:id
of a previously defined object:
<fx:define>
<Long fx:id="inv" fx:value="9765625"/>
</fx:define>
<inventory>
<fx:reference source="inv"/>
</inventory>
The
products
field illustrates how to populate a read-only list. The following fragment of FXML is equivalent to
invoking
bean.getProducts().addAll("widget", "gadget", "models")
:
<products>
<String fx:value="widget"/>
<String fx:value="gadget"/>
<String fx:value="models"/>
</products>
Search WWH ::
Custom Search