JavaFX 2: How to load stylesheet into a Scene subclass distributed as part of a library?


I'm subclassing many of the JavaFX 2 classes to distribute them as part of a library that will be used by others. This requires that a stylesheet (part of the library) be applied to all instances of MySceneClass (not it's real name :-) ), and I can't find the right path magic. I've tried variants of:


where com.mine.css is a package of the library: Variants I've tried include no leading slash, trimming the leading part of the path, probably a few others. But I always get the message:

WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "/com/mine/css/MySceneClass.css" not found.

I've also tried putting a stub Css class into the css package, and then using


to fetch a URL that I can pass to ...getStyleSheets.addAll(...), but when I do so I get a message like:

WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "../css/Scene.css" not found.

which is very confusing, as getResource seems to be correctly identifying the file, but I still can't load it.

This is on the current dev preview on OS X (I believe the version is 2.1 09).

Thanks for any help, Ken

1/25/2012 10:00:55 PM

I've only had luck with this syntax as found in the Ensemble sample:

1/25/2012 10:57:49 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow