JavaFX 2:如何将样式表加载到作为库的一部分分发的场景子类中?
我对许多 JavaFX 2 类进行子类化,将它们作为库的一部分分发给其他人使用。这需要将样式表(库的一部分)应用于 MySceneClass 的所有实例(不是它的真实名称:-)),并且我找不到正确的路径魔法。我尝试过以下变体:
mySceneInstance.getStylesheets.addAll("/com/mine/css/MySceneClass.css")
其中 com.mine.css 是库的包: 我尝试过的变体不包括前导斜杠,修剪路径的前导部分,可能还有其他一些。但我总是收到这样的消息:
WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "/com/mine/css/MySceneClass.css" not found.
我还尝试将一个存根 Css 类放入 css 包中,然后使用它
com.mine.css.Css.getResource("Scene.css")
来获取可以传递给 ...getStyleSheets.addAll(...) 的 URL,但是当我这样做时所以我收到这样的消息:
WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "../css/Scene.css" not found.
这非常令人困惑,因为 getResource 似乎正确识别了文件,但我仍然无法加载它。
这是 OS X 上当前的开发预览版(我相信版本是 2.1 09)。
感谢您的帮助, 肯
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:
mySceneInstance.getStylesheets.addAll("/com/mine/css/MySceneClass.css")
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
com.mine.css.Css.getResource("Scene.css")
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只幸运地使用了 Ensemble 示例中的语法:
I've only had luck with this syntax as found in the Ensemble sample:
最后找到了 Intellij IDEA CE 的问题,默认情况下,它不会将 css 文件识别为需要从源复制到目标目录的资源。将 *.css 模式添加到可识别的资源类型列表中解决了该问题。
Finally tracked down the problem to Intellij IDEA CE which, by default, does not recognize css files as a resource that needs to be copied from the source to the target dir. Adding a *.css pattern to list of recognized resource types fixed the problem.