javajavafxfxmljava-9javafx-9

How to set several default CSS stylesheet for an application with JavaFX 9 (a replace for StyleManager)?


Whose damn idea it was to exclude StyleManager without direct and clear replacement - it broke many programs as I see!

I need to make some restyling for the whole application (custom components, custom pseudo classes, custom platform-specific patches etc.). In JavaFX 8 I could use: com.sun.javafx.css.StyleManager.getInstance().addUserAgentStylesheet("MyShit.css");

But in Java 9 StyleManager is not available. So is there a way to set CSS for every scene?

Using "Application.setUserAgentStylesheet" is not an option because I don't want to lose default lookandfeel and I already call it to set MODENA style. I want to extend the default CSS not to replace it. And I don't want to rewrite the whole MODENA also (obviously).

And I really don't want to set the same stylesheet for every form/scene in the application manually (or add it to every FXML file). There many forms, dynamically constructed dialogs. And the main reason, there are parts (and libraries) which is shared between several applications so I don't want to hardcode any stylesheets (which might have different names and paths for different applications).

So I need a way to set an additional stylesheet for every possible scene of the application in one point of the program. Is that possible in FX9?

P.S. I looked into custom FXML loaders, CSS loaders, scene loaders and other ways to intercept scene creation - there is no way!


Solution

  • It's just another lack of JavaFX - simply use the JVM parameter below to make the StyleManager accessible.

    --add-exports=javafx.graphics/com.sun.javafx.css=ALL-UNNAMED