Java Reference
In-Depth Information
In the style sheet file, besides using the fully qualified class name for javafx
.scene.text.Text , you can also just use the basic class name Text . This is true
for all the standard JavaFX user interface classes. Notice that when you use the
fully qualified class name, it needs to be enclosed in double quotes. This is so the
CSS parser can distinguish it from a CSS class selector. The alternative style for
our text example is shown in Listing 5.7.
Listing 5.7
Style Sheet - Short Class Name for JavaFX Standard Classes
/* MyStyle.css *./
Text#MainText {
fill: navy;
font:bold italic 35pt "sans-serif";
}
Another way to define styles is to use CSS class selectors. You do this by defin-
ing a CSS class selector, then by using it with the styleClass instance variable
of the display node. Listing 5.8 shows how to create a CSS class of PrimaryText
on the Text class.
Listing 5.8
Style Sheet CSS Class Selector
/* MyStyle.css *./
Text.PrimaryText {
fill: navy;
font:bold italic 35pt "sans-serif";
}
This is then used in the object literal for the text by initializing the styleClass
instance variable with the name of the CSS class. Listing 5.9 shows how to use
this in a JavaFX object literal.
Listing 5.9
JavaFX styleClass for CSS Class Selector
/* Main.fx */
...
...
Text {
styleClass: "PrimaryText"
x: 10, y: 30
content: "This shows my style"
}
...
 
Search WWH ::




Custom Search