Images imported in scene builder is not getting displayed while executed in netbeans


All the functionalities are working fine except this image display. But in Scene builder preview its working fine. Can someone help in this??

2/1/2014 11:59:44 AM

Accepted Answer

maybe you linked images from outside the projectdirectory, i made a small and simple example, which works quite well.

Put your image into the same package, where you placed your fxml file and link it again in Scene Builder to the new location.

enter image description here

Here's a little code:

package com.example.images;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class App extends Application{

    public void start(Stage stage) throws Exception {
        Parent parent = FXMLLoader.load(getClass().getResource("images.fxml"));
        stage.setTitle("Image set in Scene Builder");
        Scene scene = new Scene(parent);

    public static void main(String[] args) {

And the fxml File:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" fx:id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="" xmlns="" fx:controller="com.example.images.controller.MainController">
    <ImageView fitHeight="337.875" fitWidth="540.6" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
        <Lighting surfaceScale="5.0">
            <Shadow />
            <javafx.scene.effect.Light.Distant azimuth="-135.0" />
        <Image url="@1.png" backgroundLoading="true" />


2/1/2014 2:12:14 PM

I have faced two cases for this problem. One is that maybe you don't have your images in a "recources" folder in your "src" directory. Two, if you do, then probably your IDE just has not read it yet. For example if you're using Eclipse, expand your recources folder on File Explorer. If your image is not in there then right click on the folder and select refresh. You should be fine after that.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow