Using the setStyle() method

The Node.setStyle(String style) method can be called directly from the JavaFX code to apply CSS to the given node. 

This method is not recommended for use in production applications due to worse performance than other approaches.

But it becomes irreplaceable if you need to build a style on the fly. This approach is very useful for studying styles or trying to find a perfect value for a style. 

Let's see it in the example:

// chapter6/basics/SetStyleDemo.javapublic void start(Stage stage) {    GridPane root = new GridPane();    root.setPadding(new Insets(10));    root.setHgap(5);    root.setVgap(5);    Scene scene = new Scene(root, 300, 250);    TextField fontSize, width, height; root.addRow(0, new Label("font size"), fontSize = ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.