JavaFX SceneBuilder ImageView not working(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.
这篇关于JavaFX SceneBuilder ImageView 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JavaFX SceneBuilder ImageView 不工作


基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01