Understanding cascading – the priority scheme for different styling methods

The word cascading in the Cascading Style Sheets (CSS) refers to the priority scheme or order to apply different styles to the one Node.

If styles are applied to the Node by different means, JavaFX will apply them according to the following rules of priority:

  1. A style from Application.setUserAgentStylesheet()
  2. A value set by an API call such as btn.setMinHeight(50);
  3. A style from a CSS file set through Scene.getStylesheets() or Parent.getStylesheets()
  4. A style from Node.setStyle() overrides all the above items

Thus, setStyle() overrides any other style settings. And it really does: once you have changed a property with setStyle(), you can't change it by any other means. ...

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.