title: Setting the background of a GridPane (with or without JavaFx Scene Builder)
body: <p>I'm new to javafx and I am trying to set the background of a GridPane to an image(, or behind the GridPane). Setting the image in the fxml-file itself did not work. I tried to do this with the JavaFx Scene builder provided by oracle first and then later by manually adding this to the code with: <code>&lt;GridPane style="-fx-background-image: url('board.jpg' ); ...</code>, but this resulted to nothing being changed when running the application.</p>
  
  <p>I then resorted to setting the background image in the main-method and not the fxml-file. When I try to access the GridPane object (with getNamespace().get()) I get <em>null</em> back, so my problem here is that I can't seem to access the object to then set it's background to the image I want.</p>
  
  <p>This what I tried most recently:</p>
  
  <p><strong>sample.fxml</strong> </p>
  
  <pre><code>&lt;GridPane id="pain"...
  </code></pre>
  
  <p><strong>main.java</strong></p>
  
  <pre><code>FXMLLoader fxmlloader = new FXMLLoader(getClass().getResource("sample.fxml"));
  Parent root = fxmlloader.load();
  GridPane pane = (GridPane)fxmlloader.getNamespace().get("pain");
  pane.setStyle("-fx-background-image: url('image.jpg');");
  </code></pre>
  
  <p>I already tried to find how to do this without success here:</p>
  
  <p><a href="https://stackoverflow.com/questions/12324799/javafx-2-0-fxml-strange-lookup-behaviour">JavaFX 2.0 + FXML - strange lookup behaviour</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9738146/javafx-how-to-set-scene-background-image">JavaFX How to set scene background image</a></p>