JavaFX SceneBuilder ImageView 不工作 [英] JavaFX SceneBuilder ImageView not working

查看:49
本文介绍了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 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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