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 不工作
基础教程推荐
- 将 double 转换为 Int,向下舍入 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
