Referring to resources from FXML

Certain JavaFX controls work with external resources. For example, the Image class requires a URL of the represented image. To simplify work with such controls in FXML, you can refer to a path relative to the FXML location by using the @ prefix. Refer to the following code snippet:

<ImageView>
    <Image url="@image.png"/>
</ImageView>

Here, JavaFX assumes that image.png is located in the same folder (either on disk or in a JAR) as the FXML.

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.