Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Example usage</em></p> <pre><code>FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource("/main.fxml")); Parent content = loader.load(); </code></pre> <p><em>Location resolution options</em></p> <ol> <li><p>Put all of your fxml in the src/main/resources directory.</p> <pre><code>loader.setLocation(getClass().getResource("/main.fxml")); </code></pre></li> <li><p>Put all of your fxml in a src/main/resources/fxml directory. </p> <pre><code>loader.setLocation(getClass().getResource("/fxml/main.fxml")); </code></pre></li> <li><p>Place fxml in a corresponding resource directory; e.g. src/main/resources/com/mycompany/myapp. </p> <pre><code>loader.setLocation(getClass().getResource("main.fxml")); </code></pre></li> </ol> <p>The last option assumes that the class from which you are loading the fxml is in the same relative location in the corresponding Java source hierarchy. For example, you might invoke the last load command from source <code>com.mycompany.myapp.Main.java</code>.</p> <p><em>FXMLLoader usage recommendations</em></p> <ol> <li><p>Instantiate an FXMLLoader via <code>new FXMLLoader()</code> rather than using the <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#load-java.net.URL-" rel="noreferrer">static methods on the FXMLLoader</a>. </p> <ul> <li>The static methods become confusing when you want to <a href="http://docs.oracle.com/javafx/2/api/javafx/fxml/FXMLLoader.html#getController%28%29" rel="noreferrer">get values</a> (like instantiated controllers) out of a loader.</li> </ul></li> <li><p><a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#setLocation-java.net.URL-" rel="noreferrer">Set the location</a> on the instantiated FXMLLoader and call <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#load--" rel="noreferrer"><code>load()</code></a> rather than loading from a stream using <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#load-java.io.InputStream-" rel="noreferrer"><code>load(stream)</code></a>.</p> <ul> <li>Setting a URL based location on the loader allows for resolution of relative resources loaded in fxml and css files. Relative resources do not resolve for a stream based constructor.</li> </ul></li> <li><p>To derive a location based upon a class, use <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-" rel="noreferrer"><code>getClass().getResource()</code></a>, as it is URL based, rather than <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResourceAsStream-java.lang.String-" rel="noreferrer"><code>getClass().getResourceAsStream()</code></a> which is stream based.</p></li> </ol> <p><em>IDE and Build Settings</em></p> <p>Ensure that your IDE or build tool is copying the fxml files from the resource directory to the build output directory. For understanding Intellij settings for this, see: <a href="https://stackoverflow.com/questions/23421325/how-to-convert-a-normal-java-project-in-intellij-into-a-javafx-project">How to convert a normal java project in intellij into a JavaFx project</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload