Java Reference
In-Depth Information
When the code for the form containing the CSS styling is executed, it will produce the form
shown in the next screenshot:
How it works...
Cascading Style Sheets (CSS) facilitate the separation of visual content in the scene
graph from the styling of that content. CSS provides a declarative language to express the
presentation and formatting semantics of the associated content. All Node instances in
JavaFX expose the property style:String, which lets you inject CSS directives directly in
your JavaFX code, similar to the style attribute in an HTML document.
In our previous code snippet, we used the style property to format the GUI elements in the
form. The first element formatted is the Text instance. As you can see, using the CSS, you
can specify all formatting attributes about the text including font-family, size, and weight.
The code also shows you how to apply inline CSS styling directives to controls such as Label ,
TextInput , and Button instances.
There's more...
JavaFX CSS
Due to its wide adoption, CSS has been ported to non-XML-based languages, such as JavaFX.
CSS in JavaFX is similar to the W3C's CSS language only in functionality. The JavaFX's version
of CSS works as a declarative meta-programming language that lets developers declare
formatting and layout directives of JavaFX nodes. When you declare a style in CSS, the JavaFX
runtime matches the CSS property name to the node's property with the same name. So,
when you see:
var circle = Circle {
style:"center-x: 140; "
}
 
Search WWH ::




Custom Search