JavaFX provides extensive support for styling components with CSS. You can create JavaFX control skins using both inline and externalized style declarations. The JavaFX style dialect supports both standard and JavaFX-specific constructs. The following samples show how styles may be applied.
Using the JavaFX CSS engine, you can specify the look and feel of your text component as shown in the example below. Note that all of the properties are specified in the style property rather than individual class instance properties.
The snippet above would produce the text shown in the following figure:
Besides text, you can also style shapes using CSS declarations. The following styles a Rectangle instance:
The previous snippet produces a rectangle as shown in the figure below:
Besides text, you can also style shapes using CSS declarations. The following styles a Circle instance:
The previous snippet produces a circle as shown in the figure below:
Instead of doing inline CSS declarations, JavaFX also supports applying CSS from a file. Once you have created your CSS file, you can apply it to your application using the stylesheets property of the Scene object as shown below:
Styles can then be referred to using the styleClass property on the node as follows: