public final void applyCss ()

If required, apply styles to this Node and its children, if any. This method does not normally need to be invoked directly but may be used in conjunction with Parent.layout() to size a Node before the next pulse, or if the Scene is not in a javafx.stage.Stage.

Provided that the Node's Scene is not null, CSS is applied to this Node regardless of whether this Node's CSS state is clean. CSS styles are applied from the top-most parent of this Node whose CSS state is other than clean, which may affect the styling of other nodes. This method is a no-op if the Node is not in a Scene. The Scene does not have to be in a Stage.

This method does not invoke the Parent.layout() method. Typically, the caller will use the following sequence of operations.


     parentNode.applyCss();
     parentNode.layout();
 

As a more complete example, the following code uses applyCss() and layout() to find the width and height of the Button before the Stage has been shown. If either the call to applyCss() or the call to layout() is commented out, the calls to getWidth() and getHeight() will return zero (until some time after the Stage is shown).


  @Override
 public void start(Stage stage) throws Exception {

    Group root = new Group();
    Scene scene = new Scene(root);

    Button button = new Button("Hello World");
    root.getChildren().add(button);

    root.applyCss();
    root.layout();

    double width = button.getWidth();
    double height = button.getHeight();

    System.out.println(width + ", " + height);

    stage.setScene(scene);
    stage.show();
 }
 

Since:  JavaFX 8.0