GoXR3Plus GoXR3Plus - 2 months ago 27
Java Question

JavaFX How set ImageView from SceneBuilder

As i see in

you can set graphic for
(though that image will not work if you export the project as .jar and you have the image into the jar).

1)I want to set images for some fxml buttons through
but i can't find anything about that.

2)Also it will be usefull if you provide info on how to do with
what i do with
,so i have not to do this on the java file manually.


Both answers from Fabian and are John Vernee are correct each one for question 1 and 2 but i can choose only one.

The structure of resources folder:

enter image description here


In SceneBuilder drag the graphic node you want to use (in this case ImageView) from the Library to the Button in the Hierarchy view. Drop it there and you should see the graphic node displayed as a child of the Button.

This will result in a fxml like this

<Button mnemonicParsing="false" text="Button">
        <ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />

By using the gear button next to the image property of the ImageView you can specify a image url starting with @ by selecting Switch to document relative path. Input image.png for the url @image.png. Saving the fxml to the correct location relative to the image will display the image in SceneBuilder.