[英]JavaFX setting a background via CSS
I want to set a background to a group, which is the root for the scene. 我想为组设置背景,这是场景的根源。 I tried this code, but the image does not appear. 我尝试了此代码,但是图像没有出现。 The image all.jpg is in the same Sourcefolder than the Main.java file. 图像all.jpg与Main.java文件位于同一Sourcefolder中。 Could anyone help me, thank a lot 谁能帮我,非常感谢
Group root = new Group();
String image = Main.class.getResource("all.jpg").toExternalForm();
root.setStyle("-fx-background-image: url('" + image + "') ");
A Group
does not provide the ability to set a background through CSS
. Group
无法通过CSS
设置背景。 You need to use something which extends from Region
to do that. 您需要使用从Region
扩展来的功能。 Probably you can use a Pane
which does more or like the same thing and can be styled with a background through CSS. 可能您可以使用做更多或喜欢相同事情的Pane
,并且可以通过CSS设置背景样式。
If you want to see whats possible for every component the CSS reference guide is the best way. 如果您想了解每个组件的功能,那么CSS参考指南就是最好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.