beeef
beeef

Reputation: 2702

JavaFX SceneBuilder ImageView not working

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?

Upvotes: 6

Views: 20712

Answers (7)

I fixed putting the image at SRC folder, when I tried to load from another folder nothing happens. My old folder was inside my OneDrive.

Upvotes: 0

Thanos
Thanos

Reputation: 45

This is because you haven't added jfoenix jar in your program. Add jfoenix jar to your project [xdezo.com][1]

Upvotes: -2

Bouteina
Bouteina

Reputation: 1

Path From Content Root src/main/resources/assets/POMME.png =

 <Image url="@../../../assets/POMME.png" />

Upvotes: 0

jojo
jojo

Reputation: 11

Just try to refresh Eclipse's System Explorer. I solved it this way.

Upvotes: 1

Max
Max

Reputation: 141

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.

Upvotes: 8

jlaurens
jlaurens

Reputation: 587

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

Upvotes: 4

Jayawickrama
Jayawickrama

Reputation: 11

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" />

Upvotes: 1

Related Questions