Using global JavaFX style sheets

You can use the  Application.setUserAgentStylesheet("/path/to/css") method to apply CSS files to all Scenes in your application simultaneously.

This method is also used by JavaFX itself to apply default CSS. You can always return to default CSS by calling  Application.setUserAgentStylesheet(null);.

Currently, there are the following global style sheets by default, accessible by the predefined constants:

Application.setUserAgentStylesheet(STYLESHEET_CASPIAN); // JavaFX 2 and older default styleApplication.setUserAgentStylesheet(STYLESHEET_MODENA);  // default style since JavaFX 8

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.