Class FXMLLoader
- javafx.fxml.FXMLLoader
public class FXMLLoader extends Object
Since:
JavaFX 2.0
-
Field Summary
Fields Modifier and Type Field and Description static StringARRAY_COMPONENT_DELIMITERDelimiter for arrays as valuesstatic StringBI_DIRECTIONAL_BINDING_PREFIXPrefix for bidirectional-binding expression resolutionstatic StringBI_DIRECTIONAL_BINDING_SUFFIXSuffix for bidirectional-binding expression resolutionstatic StringBINDING_EXPRESSION_PREFIXPrefix for binding expression resolutionstatic StringBINDING_EXPRESSION_SUFFIXSuffix for binding expression resolutionstatic StringCHANGE_EVENT_HANDLER_SUFFIXSuffix for property change/invalidation handlersstatic StringCONTROLLER_KEYWORDA key for controller in namespace mapstatic StringCONTROLLER_METHOD_PREFIXPrefix for controller method resolutionstatic StringCONTROLLER_SUFFIXA suffix for controllers of included fxml files.static StringCOPY_SOURCE_ATTRIBUTE<fx:copy> 'source' attributestatic StringCOPY_TAGThe tag name of <fx:copy>static StringDEFAULT_CHARSET_NAMEThe character set used when character set is not explicitly specifiedstatic StringDEFINE_TAGThe tag name of <fx:define>static StringESCAPE_PREFIXEscape prefix for escaping special characters inside attribute values.static StringEVENT_HANDLER_PREFIXThe prefix of event handler attributesstatic StringEVENT_KEYThe name of the Event object in event handler scriptsstatic StringEXPRESSION_PREFIXPrefix for (variable) expression resolutionstatic StringFX_CONSTANT_ATTRIBUTEThe tag name of 'fx:constant'static StringFX_CONTROLLER_ATTRIBUTEThe name of fx:controller attribute of a rootstatic StringFX_FACTORY_ATTRIBUTEThe name of 'fx:factory' attributestatic StringFX_ID_ATTRIBUTEThe name of fx:id attributestatic StringFX_NAMESPACE_PREFIXPrefix of 'fx' namespacestatic StringFX_NAMESPACE_VERSIONContains the current fx namepsace versionstatic StringFX_VALUE_ATTRIBUTEThe name of fx:value attributestatic StringIMPORT_PROCESSING_INSTRUCTIONThe tag name of import processing instructionstatic StringINCLUDE_CHARSET_ATTRIBUTE<fx:include> 'charset' attributestatic StringINCLUDE_RESOURCES_ATTRIBUTE<fx:include> 'resources' attributestatic StringINCLUDE_SOURCE_ATTRIBUTE<fx:include> 'source' attributestatic StringINCLUDE_TAGThe tag name of <fx:include>static StringINITIALIZE_METHOD_NAMEThe name of initialize methodstatic StringJAVAFX_VERSIONContains the current javafx versionstatic StringLANGUAGE_PROCESSING_INSTRUCTIONThe tag name of language processing instructionstatic StringLOCATION_KEYA key for location URL in namespace mapstatic StringNULL_KEYWORDValue that represents 'null'static StringREFERENCE_SOURCE_ATTRIBUTE<fx:reference> 'source' attributestatic StringREFERENCE_TAGThe tag name of <fx:reference>static StringRELATIVE_PATH_PREFIXPrefix for relative location resultionstatic StringRESOURCE_KEY_PREFIXPrefix for resource resolutionstatic StringRESOURCES_KEYA key for ResourceBundle in namespace mapstatic StringROOT_TAGThe tag name of <fx:root>static StringROOT_TYPE_ATTRIBUTE<fx:root> 'type' attributestatic StringSCRIPT_CHARSET_ATTRIBUTE<fx:script> 'charset' attributestatic StringSCRIPT_SOURCE_ATTRIBUTE<fx:script> 'source' attributestatic StringSCRIPT_TAGThe tag name of <fx:script>
-
Constructor Summary
Constructors Constructor and Description FXMLLoader()Creates a new FXMLLoader instance.FXMLLoader(Charset charset)Creates a new FXMLLoader instance.FXMLLoader(URL location)Creates a new FXMLLoader instance.FXMLLoader(URL location, ResourceBundle resources)Creates a new FXMLLoader instance.FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory)Creates a new FXMLLoader instance.FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory)Creates a new FXMLLoader instance.FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset)Creates a new FXMLLoader instance.FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset, LinkedList<FXMLLoader> loaders)Creates a new FXMLLoader instance.
-
Method Summary
All MethodsStatic MethodsInstance MethodsConcrete MethodsDeprecated Methods Modifier and Type Method and Description booleanequals(Object obj)BuilderFactorygetBuilderFactory()Returns the builder factory used by this loader.CharsetgetCharset()Returns the character set used by this loader.ClassLoadergetClassLoader()Returns the classloader used by this serializer.<T> TgetController()Returns the controller associated with the root object.Callback<Class<?>,Object>getControllerFactory()Returns the controller factory used by this serializer.static ClassLoadergetDefaultClassLoader()Returns the default class loader.URLgetLocation()Returns the location used to resolve relative path attribute values.ObservableMap<String,Object>getNamespace()Returns the namespace used by this loader.ResourceBundlegetResources()Returns the resources used to resolve resource key attribute values.<T> TgetRoot()Returns the root of the object hierarchy.<T> Tload()Loads an object hierarchy from a FXML document.<T> Tload(InputStream inputStream)Loads an object hierarchy from a FXML document.static <T> Tload(URL location)Loads an object hierarchy from a FXML document.static <T> Tload(URL location, ResourceBundle resources)Loads an object hierarchy from a FXML document.static <T> Tload(URL location, ResourceBundle resources, BuilderFactory builderFactory)Loads an object hierarchy from a FXML document.static <T> Tload(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory)Loads an object hierarchy from a FXML document.static <T> Tload(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset)Loads an object hierarchy from a FXML document.static Class<?>loadType(String className)Deprecated.This method now delegates togetDefaultClassLoader().static Class<?>loadType(String packageName, String className)Deprecated.This method now delegates togetDefaultClassLoader().voidsetBuilderFactory(BuilderFactory builderFactory)Sets the builder factory used by this loader.voidsetCharset(Charset charset)Sets the charset used by this loader.voidsetClassLoader(ClassLoader classLoader)Sets the classloader used by this serializer and clears any existing importsvoidsetController(Object controller)Sets the controller associated with the root object.voidsetControllerFactory(Callback<Class<?>,Object> controllerFactory)Sets the controller factory used by this serializer.static voidsetDefaultClassLoader(ClassLoader defaultClassLoader)Sets the default class loader.voidsetLocation(URL location)Sets the location used to resolve relative path attribute values.voidsetResources(ResourceBundle resources)Sets the resources used to resolve resource key attribute values.voidsetRoot(Object root)Sets the root of the object hierarchy.
-
Field Detail
-
DEFAULT_CHARSET_NAME
public static final String DEFAULT_CHARSET_NAME
The character set used when character set is not explicitly specifiedSee Also:
-
LANGUAGE_PROCESSING_INSTRUCTION
public static final String LANGUAGE_PROCESSING_INSTRUCTION
The tag name of language processing instructionSee Also:
-
IMPORT_PROCESSING_INSTRUCTION
public static final String IMPORT_PROCESSING_INSTRUCTION
The tag name of import processing instructionSee Also:
-
FX_NAMESPACE_PREFIX
public static final String FX_NAMESPACE_PREFIX
Prefix of 'fx' namespaceSee Also:
-
FX_CONTROLLER_ATTRIBUTE
public static final String FX_CONTROLLER_ATTRIBUTE
The name of fx:controller attribute of a rootSee Also:
-
FX_ID_ATTRIBUTE
public static final String FX_ID_ATTRIBUTE
The name of fx:id attributeSee Also:
-
FX_VALUE_ATTRIBUTE
public static final String FX_VALUE_ATTRIBUTE
The name of fx:value attributeSee Also:
-
FX_CONSTANT_ATTRIBUTE
public static final String FX_CONSTANT_ATTRIBUTE
The tag name of 'fx:constant'Since:
JavaFX 2.2
See Also:
-
FX_FACTORY_ATTRIBUTE
public static final String FX_FACTORY_ATTRIBUTE
The name of 'fx:factory' attributeSee Also:
-
INCLUDE_TAG
public static final String INCLUDE_TAG
The tag name of <fx:include>See Also:
-
INCLUDE_SOURCE_ATTRIBUTE
public static final String INCLUDE_SOURCE_ATTRIBUTE
<fx:include> 'source' attributeSee Also:
-
INCLUDE_RESOURCES_ATTRIBUTE
public static final String INCLUDE_RESOURCES_ATTRIBUTE
<fx:include> 'resources' attributeSee Also:
-
INCLUDE_CHARSET_ATTRIBUTE
public static final String INCLUDE_CHARSET_ATTRIBUTE
<fx:include> 'charset' attributeSee Also:
-
SCRIPT_TAG
public static final String SCRIPT_TAG
The tag name of <fx:script>See Also:
-
SCRIPT_SOURCE_ATTRIBUTE
public static final String SCRIPT_SOURCE_ATTRIBUTE
<fx:script> 'source' attributeSee Also:
-
SCRIPT_CHARSET_ATTRIBUTE
public static final String SCRIPT_CHARSET_ATTRIBUTE
<fx:script> 'charset' attributeSee Also:
-
DEFINE_TAG
public static final String DEFINE_TAG
The tag name of <fx:define>See Also:
-
REFERENCE_TAG
public static final String REFERENCE_TAG
The tag name of <fx:reference>See Also:
-
REFERENCE_SOURCE_ATTRIBUTE
public static final String REFERENCE_SOURCE_ATTRIBUTE
<fx:reference> 'source' attributeSee Also:
-
ROOT_TAG
public static final String ROOT_TAG
The tag name of <fx:root>Since:
JavaFX 2.2
See Also:
-
ROOT_TYPE_ATTRIBUTE
public static final String ROOT_TYPE_ATTRIBUTE
<fx:root> 'type' attributeSince:
JavaFX 2.2
See Also:
-
COPY_TAG
public static final String COPY_TAG
The tag name of <fx:copy>See Also:
-
COPY_SOURCE_ATTRIBUTE
public static final String COPY_SOURCE_ATTRIBUTE
<fx:copy> 'source' attributeSee Also:
-
EVENT_HANDLER_PREFIX
public static final String EVENT_HANDLER_PREFIX
The prefix of event handler attributesSee Also:
-
EVENT_KEY
public static final String EVENT_KEY
The name of the Event object in event handler scriptsSee Also:
-
CHANGE_EVENT_HANDLER_SUFFIX
public static final String CHANGE_EVENT_HANDLER_SUFFIX
Suffix for property change/invalidation handlersSee Also:
-
NULL_KEYWORD
public static final String NULL_KEYWORD
Value that represents 'null'See Also:
-
ESCAPE_PREFIX
public static final String ESCAPE_PREFIX
Escape prefix for escaping special characters inside attribute values. Serves as an escape forESCAPE_PREFIX,RELATIVE_PATH_PREFIX, #RESOURCE_KEY_PREFIX, {@link #EXPRESSION_PREFIX}, {@link #BI_DIRECTIONAL_BINDING_PREFIX}Since:
JavaFX 2.1
See Also:
-
RELATIVE_PATH_PREFIX
public static final String RELATIVE_PATH_PREFIX
Prefix for relative location resultionSee Also:
-
RESOURCE_KEY_PREFIX
public static final String RESOURCE_KEY_PREFIX
Prefix for resource resolutionSee Also:
-
EXPRESSION_PREFIX
public static final String EXPRESSION_PREFIX
Prefix for (variable) expression resolutionSee Also:
-
BINDING_EXPRESSION_PREFIX
public static final String BINDING_EXPRESSION_PREFIX
Prefix for binding expression resolutionSee Also:
-
BINDING_EXPRESSION_SUFFIX
public static final String BINDING_EXPRESSION_SUFFIX
Suffix for binding expression resolutionSee Also:
-
BI_DIRECTIONAL_BINDING_PREFIX
public static final String BI_DIRECTIONAL_BINDING_PREFIX
Prefix for bidirectional-binding expression resolutionSince:
JavaFX 2.1
See Also:
-
BI_DIRECTIONAL_BINDING_SUFFIX
public static final String BI_DIRECTIONAL_BINDING_SUFFIX
Suffix for bidirectional-binding expression resolutionSince:
JavaFX 2.1
See Also:
-
ARRAY_COMPONENT_DELIMITER
public static final String ARRAY_COMPONENT_DELIMITER
Delimiter for arrays as valuesSince:
JavaFX 2.1
See Also:
-
LOCATION_KEY
public static final String LOCATION_KEY
A key for location URL in namespace mapSince:
JavaFX 2.2
See Also:
-
RESOURCES_KEY
public static final String RESOURCES_KEY
A key for ResourceBundle in namespace mapSince:
JavaFX 2.2
See Also:
-
CONTROLLER_METHOD_PREFIX
public static final String CONTROLLER_METHOD_PREFIX
Prefix for controller method resolutionSee Also:
-
CONTROLLER_KEYWORD
public static final String CONTROLLER_KEYWORD
A key for controller in namespace mapSince:
JavaFX 2.1
See Also:
-
CONTROLLER_SUFFIX
public static final String CONTROLLER_SUFFIX
A suffix for controllers of included fxml files. The full key is stored in namespace map.Since:
JavaFX 2.2
See Also:
-
INITIALIZE_METHOD_NAME
public static final String INITIALIZE_METHOD_NAME
The name of initialize methodSince:
JavaFX 2.2
See Also:
-
JAVAFX_VERSION
public static final String JAVAFX_VERSION
Contains the current javafx versionSince:
JavaFX 8.0
-
FX_NAMESPACE_VERSION
public static final String FX_NAMESPACE_VERSION
Contains the current fx namepsace versionSince:
JavaFX 8.0
See Also:
-
-
Constructor Detail
-
FXMLLoader
public FXMLLoader()
Creates a new FXMLLoader instance.
-
FXMLLoader
public FXMLLoader(URL location)
Creates a new FXMLLoader instance.Parameters:
location-Since:
JavaFX 2.1
-
FXMLLoader
public FXMLLoader(URL location, ResourceBundle resources)Creates a new FXMLLoader instance.Parameters:
location-Since:
JavaFX 2.1
-
FXMLLoader
public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory)Creates a new FXMLLoader instance.Parameters:
location-Since:
JavaFX 2.1
-
FXMLLoader
public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory)Creates a new FXMLLoader instance.Parameters:
location-Since:
JavaFX 2.1
-
FXMLLoader
public FXMLLoader(Charset charset)
Creates a new FXMLLoader instance.Parameters:
charset-
-
FXMLLoader
public FXMLLoader(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset)Creates a new FXMLLoader instance.Parameters:
location-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-Since:
JavaFX 2.1
-
-
Method Detail
-
getLocation
public URL getLocation()
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-
-
getResources
public ResourceBundle getResources()
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-
-
getNamespace
public ObservableMap<String,Object> getNamespace()
Returns the namespace used by this loader.
-
getRoot
public <T> T getRoot()
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
-
equals
public boolean equals(Object obj)
-
getController
public <T> T getController()
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.
-
setBuilderFactory
public void setBuilderFactory(BuilderFactory builderFactory)
Sets the builder factory used by this loader.Parameters:
builderFactory-
-
getControllerFactory
public Callback<Class<?>,Object> getControllerFactory()
Returns the controller factory used by this serializer.Since:
JavaFX 2.1
-
setControllerFactory
public void setControllerFactory(Callback<Class<?>,Object> controllerFactory)
Sets the controller factory used by this serializer.Parameters:
controllerFactory-Since:
JavaFX 2.1
-
getCharset
public Charset getCharset()
Returns the character set used by this loader.
-
setCharset
public void setCharset(Charset charset)
Sets the charset used by this loader.Parameters:
charset-Since:
JavaFX 2.1
-
getClassLoader
public ClassLoader getClassLoader()
Returns the classloader used by this serializer.Since:
JavaFX 2.1
-
setClassLoader
public void setClassLoader(ClassLoader classLoader)
Sets the classloader used by this serializer and clears any existing importsParameters:
classLoader-Since:
JavaFX 2.1
-
load
public <T> T load() throws IOExceptionLoads an object hierarchy from a FXML document. The location from which the document will be loaded must have been set by a prior call tosetLocation(URL).When the "template" flag is set to false (the default), this method will clear the imports before loading the document's content. When "template" is true, the imports will not be cleared, and the root value will be set to null before the content is loaded. This helps improve performance on subsequent loads by eliminating the overhead of loading the classes referred to by the document.
-
load
public <T> T load(InputStream inputStream) throws IOExceptionLoads an object hierarchy from a FXML document.Parameters:
inputStream- An input stream containing the FXML data to load.Returns:
The loaded object hierarchy.
Throws:
-
loadType
public static Class<?> loadType(String packageName, String className) throws ClassNotFoundExceptionDeprecated. This method now delegates togetDefaultClassLoader().Loads a type using the default class loader.Parameters:
packageName-Throws:
-
loadType
public static Class<?> loadType(String className) throws ClassNotFoundExceptionDeprecated. This method now delegates togetDefaultClassLoader().Loads a type using the default class loader.Parameters:
className-Throws:
-
getDefaultClassLoader
public static ClassLoader getDefaultClassLoader()
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 IOExceptionLoads an object hierarchy from a FXML document.Parameters:
location-Throws:
-
load
public static <T> T load(URL location, ResourceBundle resources) throws IOExceptionLoads an object hierarchy from a FXML document.Parameters:
location-Throws:
-
load
public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory) throws IOExceptionLoads an object hierarchy from a FXML document.Parameters:
location-Throws:
-
load
public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory) throws IOExceptionLoads an object hierarchy from a FXML document.
-
load
public static <T> T load(URL location, ResourceBundle resources, BuilderFactory builderFactory, Callback<Class<?>,Object> controllerFactory, Charset charset) throws IOExceptionLoads an object hierarchy from a FXML document.
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.