title: Setting background image by javafx code (not css)
body: <p>I'm trying to set an image as the background using this code:</p>
  
  <pre><code>root.setStyle("-fx-background-image: url('splash.jpg'); 
                 -fx-background-position: center center; 
                 -fx-background-repeat: stretch;");
  </code></pre>
  
  <p>But it doesn't work. If I set it with CSS, it works perfectly:</p>
  
  <pre><code>root.setId("pane");
  primaryStage.getScene().getStylesheets().add(JavaFXApplication9.class.getResource("style.css").toExternalForm());
  </code></pre>
  
  <p>and CSS:</p>
  
  <pre><code>#pane{
     -fx-background-image: url('splash.jpg');
     -fx-background-repeat: stretch;   
     -fx-background-position: center center;
  }
  </code></pre>
  
  <p>All of my files (main class, CSS and image) placed into the same package.</p>
  
  <p>So, how can I set the background image using code? Or, how can I override (replace) lines about background-image of some element in CSS from application code? Thanks!</p>