Why won't an image show using FXML for JavaFX using Scenebuilder and Eclipse?


Question

I've built a simple GUI using Scenebuilder with several buttons. In SceneBuilder, everything shows up fine.

But when I run the program, in all the buttons except for one, all of their ImageViewers' images display properly. I encountered this issue before, and after cleaning the project, things showed up, but not this time. I use document references to point to the images, and all the images used are present, which is that they are all in the same directory with the fxml and controller class.

Any idea what could be the cause behind the issue?

Edit: Here's the (shortened) fxml code

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

<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>

<fx:root onMouseDragged="#onMouseDrag" onMouseEntered="#onMouseEnter" onMouseExited="#onMouseExit" prefHeight="500.0" prefWidth="600.0" type="VBox" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <ToolBar onMouseDragged="#onMouseDrag" onMouseEntered="#onMouseEnter" onMouseExited="#onMouseExit" prefHeight="0.0" prefWidth="376.0">
        <items>
            <Button fx:id="closeButton" mnemonicParsing="false" onAction="#closeWindow">
               <graphic>
                  <ImageView fitHeight="40.0" fitWidth="40.0" pickOnBounds="true" smooth="false">
                     <image>
                        <Image url="@images/close-32.png" />
                     </image>
                  </ImageView>
               </graphic>
            </Button>
        </items>
      </ToolBar>
   </children>
</fx:root>

Here's the simple controller. I explicitly call setup on the the hosting Stage

public LogViewerControllerFX() {
    Platform.setImplicitExit(false);
}

public void setup() {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
            "LogViewerFX.fxml"));

    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);

    try {
        fxmlLoader.load();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Here's the Stage:

import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class LogViewerDialogFX extends Stage {

    public LogViewerDialogFX() {
        LogViewerControllerFX logViewController = new LogViewerControllerFX();
        logViewController.setup();  

        Scene scene = new Scene(logViewController);
        scene.setFill(Color.TRANSPARENT);
        setScene(scene);
        initStyle(StageStyle.TRANSPARENT);
        initModality(Modality.WINDOW_MODAL);
        setTitle(I18N.getText("title.logViewer"));
        getIcons().add(new Image("net/logviewer/image/logs-25.png"));
    }
}

This all happens within the JavaFX thread, of course.

1
0
7/6/2014 11:47:53 PM

Correct me if I am wrong but please take a look here:

<Image url="@images/close-32.png" />

Refers to an image in '/images/' folder. However:

getIcons().add(new Image("net/logviewer/image/logs-25.png"));

Refers to an image in '/image/' folder. As you can see, they both refers to different folder. You may want to check which one is the right one, 'image/' or 'images/' folder.

1
4/11/2016 4:21:59 PM

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