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
有人可以帮帮我吗?
推荐答案
您的问题有一个更简单的解决方案,无需添加或删除任何代码.
There's an easier solution to your problem, without the need of adding or removing any code.
在 Scene Builder 中创建 ImageView 控件并从计算机中选择图像后,选择省略号按钮旁边的齿轮"图标并选择切换到绝对路径".
Once you had created an ImageView control in Scene Builder and chosen an image from your computer, select the "gear" icon right beside the ellipses button and select "switch to absolute path".
当您运行代码时,图像将自动出现.
Image will then automatically appear when you run the code.
相关文章