JavaFX SceneBuilder ImageView not working

南笙酒味 提交于 2020-01-04 13:38:40

问题


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.

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.

The path to my gui.fxml file:

/src/gui/gui.fxml

The path to my image file:

/placeholder.png

Can anybody help me please?


回答1:


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




回答2:


There's an easier solution to your problem, without the need of adding or removing any code.

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.




回答3:


There should be @ as following in image URL. Put image file in inside project folder either same package or different package.

 <Image url="@../image/profile_pic.png" />



回答4:


This is because you haven't added jfoenix jar in your program. Add jfoenix jar to your project



来源:https://stackoverflow.com/questions/29397367/javafx-scenebuilder-imageview-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!