Question

i've a small test project using graniteds+javafx+spring. I followed this tutorial GraniteDs+JavaFx.

All works fine but if I use a fxml file in which I have some images with relative url as in this example:

<children>
    <ImageView fitHeight="32.0" fitWidth="32.0" layoutX="14.0" layoutY="14.0" onMouseClicked="#menuHome" pickOnBounds="true" preserveRatio="true">
      <image>
        <Image url="@../images/icons/home.png" />
      </image>
    </ImageView>

I've this execption:

 SEVERE: Could not show view
 javafx.fxml.LoadException: Base location is undefined.
     at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:283)
     at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:197)
     at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:570)
     at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
     at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
     at org.granite.client.tide.javafx.TideFXMLLoader.load(TideFXMLLoader.java:49)

The code that load the FXML is this:

private Parent showView(Stage stage, boolean loggedIn) {
try {               
    Parent root = (Parent) TideFXMLLoader.load(contextManager.getContext(),
         loggedIn ? "Home.fxml" : "LoginUi.fxml", loggedIn ? Home.class
        : LoginUi.class);


            Scene scene = new Scene(root);              
            stage.setScene(scene);
            stage.show();

            return root;
        } catch (Exception e) {
            log.error(e, "Could not show view");
        }
        return null;
    }

There is a way to set the base location with TideFXMLLoader?

Thanks

Was it helpful?

Solution

I know that this ask is a little old and you probably had it solved some way. But I solved it putting the following code before load fxml:

loader.setLocation(Class.class.getResource(url));

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top