Java Reference
In-Depth Information
Getting ready
The concepts presented here all deal with CSS and externalizing through CSS files. If you have
not used CSS, or are unfamiliar with JavaFX's support for CSS, it is recommended that you
review the recipe Styling your applications with CSS and Using CSS files to apply styles from
this chapter to get acquainted with JavaFX 's implementation of CSS.
This recipe is going to reuse the data form example used throughout the chapter. Refer to the
recipe Creating a form with JavaFX controls for a thorough background on this example. In this
usage, we extend the code in the form to support skinning using JavaFX CSS. In this version,
the user is able to apply one of two themes to update the look of the application.
How to do it...
Again, the code that creates the data form has been discussed in earlier recipes (see Getting
ready ). Hence, we are going to concentrate on how to update application's styles in real-time
without a restart. If you want to see the full code listing of the application, refer to ch04/
source-code/src/styling/DataFormSkinnableCss.fx .
The super abbreviated code snippet given next provides the part of the code that updates the
CSS files. This is done as follows:
var cssFile = "bluemoon.css";
...
var btnRow = HBox {
spacing:7
content:[
Button{
text:"Bluemoon.css"
action:function(){
cssFile = "bluemoon.css"
}
}
Button{text:"Autumn.css"
action:function(){
cssFile = "autumn.css";
}
}
]
}
...
Stage {
title : "Skinnable Data Input Form"
scene: scene = Scene {
 
Search WWH ::




Custom Search