Class FXMLLoader

java.lang.Object
javafx.fxml.FXMLLoader

public class FXMLLoaderextends Object
Loads an object hierarchy from an XML document. For more information, see the Introduction to FXML document.
Since:
JavaFX 2.0
  • Field Details

  • Constructor Details

    • FXMLLoader

      public FXMLLoader()
      Creates a new FXMLLoader instance.
    • FXMLLoader

      public FXMLLoader(URL location)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      Since:
      JavaFX 2.1
    • FXMLLoader

      public FXMLLoader(URL location, ResourceBundle resources)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - the resources used to resolve resource key attribute values
      Since:
      JavaFX 2.1
    • FXMLLoader

      public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - resources used to resolve resource key attribute values
      builderFactory - the builder factory used by this loader
      Since:
      JavaFX 2.1
    • FXMLLoader

      public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - resources used to resolve resource key attribute values
      builderFactory - the builder factory used by this loader
      controllerFactory - the controller factory used by this loader
      Since:
      JavaFX 2.1
    • FXMLLoader

      public FXMLLoader(Charset charset)
      Creates a new FXMLLoader instance.
      Parameters:
      charset - the character set used by this loader
    • FXMLLoader

      public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - resources used to resolve resource key attribute values
      builderFactory - the builder factory used by this loader
      controllerFactory - the controller factory used by this loader
      charset - the character set used by this loader
      Since:
      JavaFX 2.1
    • FXMLLoader

      public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset, LinkedList<FXMLLoader> loaders)
      Creates a new FXMLLoader instance.
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - resources used to resolve resource key attribute values
      builderFactory - the builder factory used by this loader
      controllerFactory - the controller factory used by this loader
      charset - the character set used by this loader
      loaders - list of loaders
      Since:
      JavaFX 2.1
  • Method Details

    • getLocation

      public URL getLocation()
      Returns the location used to resolve relative path attribute values.
      Returns:
      the location used to resolve relative path attribute values
    • setLocation

      public void setLocation(URL location)
      Sets the location used to resolve relative path attribute values.
      Parameters:
      location - the location
    • getResources

      public ResourceBundle getResources()
      Returns the resources used to resolve resource key attribute values.
      Returns:
      the resources used to resolve resource key attribute values
    • setResources

      public void setResources(ResourceBundle resources)
      Sets the resources used to resolve resource key attribute values.
      Parameters:
      resources - the resources
    • getNamespace

      public ObservableMap<String,Object> getNamespace()
      Returns the namespace used by this loader.
      Returns:
      the namespace
    • getRoot

      public <T> T getRoot()
      Returns the root of the object hierarchy.
      Type Parameters:
      T - the type of the root object
      Returns:
      the root of the object hierarchy
    • setRoot

      public void setRoot(Object root)
      Sets the root of the object hierarchy. The value passed to this method is used as the value of the <fx:root> tag. This method must be called prior to loading the document when using <fx:root>.
      Parameters:
      root - the root of the object hierarchy
      Since:
      JavaFX 2.2
    • getController

      public <T> T getController()
      Returns the controller associated with the root object.
      Type Parameters:
      T - the type of the controller
      Returns:
      the controller associated with the root object
    • setController

      public void setController(Object controller)
      Sets the controller associated with the root object. The value passed to this method is used as the value of the fx:controller attribute. This method must be called prior to loading the document when using controller event handlers when an fx:controller attribute is not specified in the document.
      Parameters:
      controller - the controller to associate with the root object
      Since:
      JavaFX 2.2
    • getBuilderFactory

      public BuilderFactory getBuilderFactory()
      Returns the builder factory used by this loader.
      Returns:
      the builder factory
    • setBuilderFactory

      public void setBuilderFactory(BuilderFactory builderFactory)
      Sets the builder factory used by this loader.
      Parameters:
      builderFactory - the builder factory
    • getControllerFactory

      public Callback<Class<?>,Object> getControllerFactory()
      Returns the controller factory used by this loader.
      Returns:
      the controller factory
      Since:
      JavaFX 2.1
    • setControllerFactory

      public void setControllerFactory(Callback<Class<?>,Object> controllerFactory)
      Sets the controller factory used by this loader.
      Parameters:
      controllerFactory - the controller factory
      Since:
      JavaFX 2.1
    • getCharset

      public Charset getCharset()
      Returns the character set used by this loader.
      Returns:
      the character set
    • setCharset

      public void setCharset(Charset charset)
      Sets the character set used by this loader.
      Parameters:
      charset - the character set
      Since:
      JavaFX 2.1
    • getClassLoader

      public ClassLoader getClassLoader()
      Returns the classloader used by this loader.
      Returns:
      the classloader
      Since:
      JavaFX 2.1
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Sets the classloader used by this loader and clears any existing imports.
      Parameters:
      classLoader - the classloader
      Since:
      JavaFX 2.1
    • getLoadListener

      public LoadListener getLoadListener()
      Returns this loader's load listener.
      Returns:
      the load listener
      Since:
      9
    • setLoadListener

      public final void setLoadListener(LoadListener loadListener)
      Sets this loader's load listener.
      Parameters:
      loadListener - the load listener
      Since:
      9
    • load

      public <T> T load() throws IOException
      Loads an object hierarchy from a FXML document. The location from which the document will be loaded must have been set by a prior call to setLocation(URL).
      Type Parameters:
      T - the type of the root object
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
      Since:
      JavaFX 2.1
    • load

      public <T> T load(InputStream inputStream) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      inputStream - an input stream containing the FXML data to load
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
    • loadType

      @Deprecatedpublic static Class<?> loadType(String packageName, String className) throws ClassNotFoundException
      Deprecated.
      This method now delegates to getDefaultClassLoader().
      Loads a type using the default class loader.
      Parameters:
      packageName - the package name of the class to load
      className - the name of the class to load
      Returns:
      the class
      Throws:
      ClassNotFoundException - if the specified class cannot be found
    • loadType

      @Deprecatedpublic static Class<?> loadType(String className) throws ClassNotFoundException
      Deprecated.
      This method now delegates to getDefaultClassLoader().
      Loads a type using the default class loader.
      Parameters:
      className - the name of the class to load
      Returns:
      the class
      Throws:
      ClassNotFoundException - if the specified class cannot be found
    • getDefaultClassLoader

      public static ClassLoader getDefaultClassLoader()
      Returns the default class loader.
      Returns:
      the default class loader
      Since:
      JavaFX 2.1
    • setDefaultClassLoader

      public static void setDefaultClassLoader(ClassLoader defaultClassLoader)
      Sets the default class loader.
      Parameters:
      defaultClassLoader - The default class loader to use when loading classes.
      Since:
      JavaFX 2.1
    • load

      public static <T> T load(URL location) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      location - the location used to resolve relative path attribute values
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
    • load

      public static <T> T load(URL location, ResourceBundle resources) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - the resources used to resolve resource key attribute values
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
    • load

      public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - the resources used to resolve resource key attribute values
      builderFactory - the builder factory used to load the document
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
    • load

      public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - the resources used to resolve resource key attribute values
      builderFactory - the builder factory used when loading the document
      controllerFactory - the controller factory used when loading the document
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
      Since:
      JavaFX 2.1
    • load

      public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset) throws IOException
      Loads an object hierarchy from a FXML document.
      Type Parameters:
      T - the type of the root object
      Parameters:
      location - the location used to resolve relative path attribute values
      resources - the resources used to resolve resource key attribute values
      builderFactory - the builder factory used when loading the document
      controllerFactory - the controller factory used when loading the document
      charset - the character set used when loading the document
      Returns:
      the loaded object hierarchy
      Throws:
      IOException - if an error occurs during loading
      Since:
      JavaFX 2.1