title: JavaFX Fxml Display Image
body: <p>I have been endeavouring to implement a JavaFX application which includes the display of an image using fxml.</p>
  <p>However, it is unclear to me how to successfully create the image url.</p>
  <p>I have tried using the ampersand annotation to create a relative path and also tried an absolute path but all are rejected by the IDE.</p>
  <p>Consequently I have created a simplified application as follows:</p>
  <p>Main.java</p>
  <pre><code>package sample;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  public class Main extends Application {
  
      @Override
      public void start(Stage primaryStage) throws Exception{
          Parent root = FXMLLoader.load(getClass().getResource(&quot;sample.fxml&quot;));
          primaryStage.setTitle(&quot;Display an Image&quot;);
          primaryStage.setScene(new Scene(root, 300, 200));
          primaryStage.show();
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  <p>sample.fxml</p>
  <pre><code>&lt;?import javafx.scene.layout.FlowPane?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;FlowPane fx:controller=&quot;sample.Controller&quot;
            xmlns:fx=&quot;http://javafx.com/fxml&quot; alignment=&quot;center&quot; hgap=&quot;10&quot; vgap=&quot;10&quot;&gt;
      &lt;ImageView fx:id=&quot;ivWoodland&quot;&gt;
          &lt;image&gt;
              &lt;Image fx:id=&quot;imgWoodland&quot; url=&quot;file:///D:/TF/ImageDemo/woodland.jpg&quot;/&gt;
  
          &lt;/image&gt;
  
      &lt;/ImageView
  </code></pre>
  <p>If anybody can inform me how to format the url it will be much appreciacted.</p>
  <p>Thanks.</p>