我正在尝试加载图像文件作为我的javafx应用程序的背景 .
Filestructure:
+F:/Repositories/DungeonCraft
|-+resources
| |-+images
| | |-splash.png
| |
| |-+styles
| |-style.css
|
|-application.jar
style.css中:
.root {
-fx-background-color: rgb(1,1,1);
-fx-background-image: url("../images/splash.png");
-fx-background-repeat: stretch;
-fx-background-size: contain;
-fx-background-position: center center;
}
我加载style.css没有问题 . 程序正确运行并显示样式,但未加载图像 . 我在控制台中收到以下错误:
Jul 13, 2015 2:54:31 AM com.sun.javafx.css.StyleManager getCachedImage
WARNING: Error loading image: file:/F:/Repositories/DungeonCraft/resources/images/splash.png
任何帮助将不胜感激 :)
2 回答
根据我的经验,您不能从项目文件的外部加载任何图像,我的意思是您可以从项目文件中创建的包中加载您想要的任何图像 . 所以你不能从外面加载其他图像 . 但...
如果你真的有兴趣通过css文件从项目的外侧加载图像,还有另外一种方法,你可以传递一个这样的网站URL:
对我而言,这似乎是一个愚蠢的错误 . 图像文件已损坏,插入新图像后,代码就像魅力一样 .
问候 :)