//rich client /
To make the price flash, we create a
Timeline, which varies the opacity of the
cell from 1.0 to 0.1 and back again over a
period of one second. The cell is made
to flash three times by setting the
cycleCount appropriately.
Skinning
Another exciting feature of the JavaFX
platform is support for cascading style
sheets (CSS). Many nodes
implement support for
CSS, including TableCell.
Adding a style sheet to
an application is pretty
simple. If you refer back to
the QuoteFXTable class in
Listing 2, you will see that
after we create the scene
in our Runnable task, we
add a reference to a CSS
file to the style sheet list of
the scene. This references a CSS file that
we include in the same package as the
QuoteFXTable class.
Now look at the QuoteFXTableNode
class again in Listing 3, specifically the
call method of the Callback class that
we pass to the setCellFactory method of
the price column. Here, we create a new
QuoteFXPriceCell object and add to the
style class list a reference to the name
we use in our CSS file to set parameters.
The CSS file is shown below:
This is very simple. We create a style
that has the name we used in the Java
code and specify a pseudo-class that
means this style will be used only on
price cells that are filled. Two param-
eters are specified: one to set the color
the cell is filled with and one to set the
color of the border.
YOUR
LOCAL JAVA
USER GROUP
NEEDS YOU
JAVA IN ACTION
You can migrate a
Swing application to
use the richness of JavaFX
without having to engage
in a complete rewrite.
Conclusion
In this article, we’ve seen
how we can migrate a
Swing application to use the richness
of JavaFX without having to engage in
a complete rewrite. We’ve modified a
sample Swing application to replace its
table component in order to make use
of the exciting functionality of JavaFX to
improve the application’s look and feel.
In Part 3, we’ll look at ways to replace
one of the configuration menus in our
sample application. </article>
Find your JUG here
ABOUT US
.fx-table:filled {
-fx-background-color:
lightblue;
-fx-border-color: black;
}
LEARN MORE
•;JavaFX documentation and tutorials
•;JavaFX 2.0 API documentation (Javadoc)
•;JavaFX showcase