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 = ...