title: How to add a CSS stylesheet in FXML
body: <p>I'd like to link a css file to my application.
  In my fxml file I use this:</p>
  
  <pre><code>  &lt;stylesheets&gt;
      &lt;URL value="@../stylesheet1.css" /&gt;
    &lt;/stylesheets&gt;
  </code></pre>
  
  <p>...and I can see a styled preview when I open the fxml file in scenebuilder. But when I try to run the application I get an error:</p>
  
  <p><em>java.net.MalformedURLException: no protocol: ../stylesheet1.css</em></p>
  
  <p>So I tested it this way:</p>
  
  <pre><code>&lt;stylesheets&gt;
      &lt;String fx:value="stylesheet1.css" /&gt;
  &lt;/stylesheets&gt;
  </code></pre>
  
  <p>and now it's other way round - the application starts and applies the css, but I don't see the preview in scenebuilder. The error message:</p>
  
  <p><em>"The file stylesheet1.css doesn't exist. Resource stylesheet1.css not found."</em></p>
  
  <p>So how do I attach the css file properly?</p>
  
  <hr>
  
  <p>Well, although my question wasn't answered why exactly it doesn't work the above way, I found a solution that works for me. In my FXML I have just the line</p>
  
  <pre><code>&lt;?scenebuilder-stylesheet ../stylesheet1.css?&gt;
  </code></pre>
  
  <p>so Scenebuilder works with that css.
  And in my main class I set the stylesheet programmatically:</p>
  
  <pre><code>Scene scene = new Scene(root);
  String css = this.getClass().getResource("../stylesheet1.css").toExternalForm(); 
  scene.getStylesheets().add(css);
  </code></pre>