6

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?

beeef
  • 2,664
  • 4
  • 17
  • 27
  • 1
    Can you add the location of the FXML and the image in the project. Please add the image path specified in the fxml as well – ItachiUchiha Apr 01 '15 at 17:58
  • Is the image placed on project's root directory and not inside a source folder? – ItachiUchiha Apr 01 '15 at 18:08
  • Yes it is. No matter where I put my image, it's displayed in Scene Builder, but not when I run my application.. – beeef Apr 01 '15 at 20:49
  • Are you passing the image path in the fxml relative to your project path? For example, a fxml present as `src/main/resources/demo.fxml` and an image present in `src/main/resources/img/image.png` must be declared in the fxml as `` – ItachiUchiha Apr 02 '15 at 14:49
  • I fixed it - the image needs to be somewhere in the src folder. I had it outside that folder, so that was not working. Thanks! – beeef Apr 02 '15 at 15:31

6 Answers6

8

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.

Max
  • 141
  • 1
  • 2
  • 7
4

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

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
jlaurens
  • 529
  • 5
  • 10
1

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

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

jojo
  • 11
  • 1
0

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

 <Image url="@../../../assets/POMME.png" />
Bouteina
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 04 '21 at 17:15
-2

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

Thanos
  • 45
  • 1
  • 10