title: JavaFX display scene background image
body: <p>I’m developing a JavaFX application on Eclipse Kepler using the built-in FX library from Java SDK1.7.0_45. I want to display a background image in a scene. Following the tutorial provided in the Java documentation, following code should work:</p>
  
  <pre><code>public class Main extends Application {
      public static void main(String[] args) {
      Application.launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
      GridPane grid = new GridPane();
      Scene scene = new Scene(grid, 300, 275);
      primaryStage.setScene(scene);
      scene.getStylesheets().add(Main.class.getResource("Login.css").toExternalForm());
      primaryStage.show();
      }
  </code></pre>
  
  <p>}</p>
  
  <p>My CSV file looks like this:</p>
  
  <pre><code>.root {
   -fx-background-image: url("background.jpg");
  </code></pre>
  
  <p>}</p>
  
  <p>But I just get a blank screen instead. I have 3 files in the src/application folder: background.jpg, Main.java and Login.css.</p>
  
  <p>I have tried adding a backslash, putting the image into a separate folder, providing an absolute path, providing several types of images, using ../application/background.jpg, changing the code to file:background.jpg, providing the URL directly into the code and dismissing the CSS file, using an imageview instead, ..... but nothing works.</p>
  
  <p>I've taken a look at several other stackoverflow links, all seemed to fail:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/9738146/javafx-how-to-set-scene-background-image">JavaFX How to set scene background image</a>  (renders a blank screen)</li>
  <li><a href="https://stackoverflow.com/questions/9851200/setting-background-image-by-javafx-code-not-css(Nullpointer">Setting background image by javafx code (not css)</a> exception)</li>
  <li><a href="https://stackoverflow.com/questions/16099427/cannot-load-image-in-javafx">Cannot load image in JavaFX</a></li>
  <li>and many more.</li>
  </ul>
  
  <p>The strange thing is, when I supply an image from a server as a hyperlink, everything works fine. Supplying the path to a local file never works though. What am I doing wrong? Can somebody show me how to display a local image? Is this a bug?</p>