Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 396
beeef Avatar asked Apr 01 '15 17:04

beeef


People also ask

How do I run Scene Builder?

Download and install the latest version of Scene Builder. In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Languages & Frameworks | JavaFX. in the Path to SceneBuilder field. In the dialog that opens, select the Scene Builder application (executable file) on your computer and click OK.

What is ImageView in JavaFX?

The ImageView is a Node used for painting images loaded with Image class. This class allows resizing the displayed image (with or without preserving the original aspect ratio) and specifying a viewport into the source image for restricting the pixels displayed by this ImageView .

How do you add text to Scene Builder?

Add a Text Field control. From the Library panel, drag a Text Field control and drop it to the right side of the Label you just added.


1 Answers

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.

like image 71
Max Avatar answered Sep 27 '22 18:09

Max