JavaFX SceneBuilder ImageView无法正常工作 [英] JavaFX SceneBuilder ImageView not working

查看:826
本文介绍了JavaFX SceneBuilder ImageView无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用SceneBuilder创建一个GUI。我在我的界面添加了一个ImageView,并正确设置了我的图像的路径。图像显示在SceneBuilder中,但是当我运行我的应用程序时,图像不存在。

I need to create a GUI with SceneBuilder. I added an ImageView to my interface and set the path to my image correctly. The image is showing inside SceneBuilder, but when I run my application, the image is not there.

我将图像放在img / placeholder.png中,然后直接进入我的根目录。无论我把它放在哪里,它都无法正常工作。

I put the image inside "img/placeholder.png", and then directly into my root directory. Doesn't matter where I put it, it isn't working.

我的gui.fxml文件的路径:

The path to my gui.fxml file:

/src/gui/gui.fxml

我的图片文件的路径:

/placeholder.png

有人可以帮助我吗?

推荐答案

某种特定的解决方案context(maven related)
给定 /src/main/resources/foo/gui.fxml / src / main / resources / foo /img/foo.png ,如果你在SceneBuilder中创建一个图像视图并将图像设置为foo.png,则url读取 @ img / foo.png 。不幸的是,图像没有显示在应用程序中。如果您将图片网址更改为 @ / foo / img / foo.png ,那么图片将不再显示在SceneBuilder中,但会在应用程序中显示。

Another solution in some particular context (maven related) Given /src/main/resources/foo/gui.fxml and /src/main/resources/foo/img/foo.png, if you create an image view in SceneBuilder and set the image to foo.png, the url reads @img/foo.png. Unfortunately the image does not show in the application. If you change the image url to @/foo/img/foo.png then the image won't show anymore in SceneBuilder but it will show in the application.

SceneBuilder 8.2.0,JDK 1.8,IntellJ IDEA 2016.1

SceneBuilder 8.2.0, JDK 1.8, IntellJ IDEA 2016.1

这篇关于JavaFX SceneBuilder ImageView无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆