//rich client /
final DoubleProperty valueA = new SimpleDoubleProperty(0);
Slider sliderA = SliderBuilder.create()
Download all listings in this issue as text
JAVA IN ACTION
Notice that moving the sliders has no
effect. Your mission will be to add code
that implements the behavior described
previously. The next sections describe
the steps you can follow to implement
Obtaining and Running the
1. Download the
NetBeans project file,
which includes the
2. Expand the project into a
directory of your choice.
3. Start NetBeans, and select
File -> Open Project.
4. From the Open Project
dialog box, navigate
to your chosen directory and open the
project, as shown in
Figure 4. If you receive a
message stating that the
jfxrt.jar file can’t be found,
click the Resolve button
and navigate to the rt/lib
folder subordinate to
where you installed the
JavaFX 2.0 SDK.
Note: You can obtain the
NetBeans IDE from the
5. To run the application,
click the Run Project icon
on the toolbar, or press the
F6 key. The Run Project
icon looks like the Play
button on a DVD player, as
shown in Figure 5.
The BindingExampleExercise application should
appear in a window, as
shown in Figure 6.
Step 1: Adding an InvalidationListener
to Detect Changes to the Value of the
To dynamically update the label text
as the top slider is moved, we’ll add an
InvalidationListener to a property that
tracks with the value of the slider.
Take a look at the code in
BindingExampleMain.java in the
which shows the starter code for this
example. We’ll show code snippets from
BindingExampleMain.java as you perform
the steps in this exercise.
Instantiate a SimpleDoubleProperty that
tracks with the value of the slider. The
starter code in BindingExampleMain.java
instantiates a SimpleDoubleProperty and
bidirectionally binds the value property
of the slider with it, as shown in Listing 1.
The SimpleDoubleProperty class is
one of several classes (for example,
SimpleBooleanProperty) in the javafx
. beans.property package that can create
properties that represent most of the
ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////////// MAY/JUNE 2012