java.lang.Object
javafx.fxml.FXMLLoader
public class FXMLLoader extends Object
Loads an object hierarchy from an XML document.
For more information, see the
Introduction to FXML
document.
- Since:
- JavaFX 2.0
-
Field Summary
Fields Modifier and Type Field Description static StringARRAY_COMPONENT_DELIMITERDelimiter for arrays as values.static StringBI_DIRECTIONAL_BINDING_PREFIXPrefix for bidirectional-binding expression resolution.static StringBI_DIRECTIONAL_BINDING_SUFFIXSuffix for bidirectional-binding expression resolution.static StringBINDING_EXPRESSION_PREFIXPrefix for binding expression resolution.static StringBINDING_EXPRESSION_SUFFIXSuffix for binding expression resolution.static StringCHANGE_EVENT_HANDLER_SUFFIXSuffix for property change/invalidation handlers.static StringCOMPILE_PROCESSING_INSTRUCTIONThe tag name of the compile processing instruction.static StringCONTROLLER_KEYWORDA key for controller in namespace map.static StringCONTROLLER_METHOD_PREFIXPrefix for controller method resolution.static StringCONTROLLER_SUFFIXA suffix for controllers of included fxml files.static StringCOPY_SOURCE_ATTRIBUTEThe <fx:copy> 'source' attribute.static StringCOPY_TAGThe tag name of <fx:copy>.static StringDEFAULT_CHARSET_NAMEThe character set used when character set is not explicitly specified.static 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 attributes.static StringEVENT_KEYThe name of the Event object in event handler scripts.static StringEXPRESSION_PREFIXPrefix for (variable) expression resolution.static StringFX_CONSTANT_ATTRIBUTEThe tag name of 'fx:constant'.static StringFX_CONTROLLER_ATTRIBUTEThe name of fx:controller attribute of a root.static StringFX_FACTORY_ATTRIBUTEThe name of 'fx:factory' attribute.static StringFX_ID_ATTRIBUTEThe name of fx:id attribute.static StringFX_NAMESPACE_PREFIXPrefix of 'fx' namespace.static StringFX_NAMESPACE_VERSIONContains the current fx namepsace version.static StringFX_VALUE_ATTRIBUTEThe name of fx:value attribute.static StringIMPORT_PROCESSING_INSTRUCTIONThe tag name of import processing instruction.static StringINCLUDE_CHARSET_ATTRIBUTEThe <fx:include> 'charset' attribute.static StringINCLUDE_RESOURCES_ATTRIBUTEThe <fx:include> 'resources' attribute.static StringINCLUDE_SOURCE_ATTRIBUTEThe <fx:include> 'source' attribute.static StringINCLUDE_TAGThe tag name of <fx:include>.static StringINITIALIZE_METHOD_NAMEThe name of initialize method.static StringJAVAFX_VERSIONContains the current javafx version.static StringLANGUAGE_PROCESSING_INSTRUCTIONThe tag name of language processing instruction.static StringLOCATION_KEYA key for location URL in namespace map.static StringNULL_KEYWORDValue that represents 'null'.static StringREFERENCE_SOURCE_ATTRIBUTEThe <fx:reference> 'source' attribute.static StringREFERENCE_TAGThe tag name of <fx:reference>.static StringRELATIVE_PATH_PREFIXPrefix for relative location resolution.static StringRESOURCE_KEY_PREFIXPrefix for resource resolution.static StringRESOURCES_KEYA key for ResourceBundle in namespace map.static StringROOT_TAGThe tag name of <fx:root>.static StringROOT_TYPE_ATTRIBUTEThe <fx:root> 'type' attribute.static StringSCRIPT_CHARSET_ATTRIBUTEThe <fx:script> 'charset' attribute.static StringSCRIPT_SOURCE_ATTRIBUTEThe <fx:script> 'source' attribute.static StringSCRIPT_TAGThe tag name of <fx:script>. -
Constructor Summary
Constructors Constructor Description FXMLLoader()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.FXMLLoader(Charset charset)Creates a new FXMLLoader instance. -
Method Summary
Modifier and Type Method 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 loader.<T> TgetController()Returns the controller associated with the root object.Callback<Class<?>,Object>getControllerFactory()Returns the controller factory used by this loader.static ClassLoadergetDefaultClassLoader()Returns the default class loader.LoadListenergetLoadListener()Returns this loader's load listener.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.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 character set used by this loader.voidsetClassLoader(ClassLoader classLoader)Sets the classloader used by this loader and clears any existing imports.voidsetController(Object controller)Sets the controller associated with the root object.voidsetControllerFactory(Callback<Class<?>,Object> controllerFactory)Sets the controller factory used by this loader.static voidsetDefaultClassLoader(ClassLoader defaultClassLoader)Sets the default class loader.voidsetLoadListener(LoadListener loadListener)Sets this loader's load listener.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 Details
-
DEFAULT_CHARSET_NAME
The character set used when character set is not explicitly specified.- See Also:
- Constant Field Values
-
LANGUAGE_PROCESSING_INSTRUCTION
The tag name of language processing instruction.- See Also:
- Constant Field Values
-
IMPORT_PROCESSING_INSTRUCTION
The tag name of import processing instruction.- See Also:
- Constant Field Values
-
COMPILE_PROCESSING_INSTRUCTION
The tag name of the compile processing instruction.- Since:
- 15
- See Also:
- Constant Field Values
-
FX_NAMESPACE_PREFIX
Prefix of 'fx' namespace.- See Also:
- Constant Field Values
-
FX_CONTROLLER_ATTRIBUTE
The name of fx:controller attribute of a root.- See Also:
- Constant Field Values
-
FX_ID_ATTRIBUTE
The name of fx:id attribute.- See Also:
- Constant Field Values
-
FX_VALUE_ATTRIBUTE
The name of fx:value attribute.- See Also:
- Constant Field Values
-
FX_CONSTANT_ATTRIBUTE
The tag name of 'fx:constant'.- Since:
- JavaFX 2.2
- See Also:
- Constant Field Values
-
FX_FACTORY_ATTRIBUTE
The name of 'fx:factory' attribute.- See Also:
- Constant Field Values
-
INCLUDE_TAG
The tag name of <fx:include>.- See Also:
- Constant Field Values
-
INCLUDE_SOURCE_ATTRIBUTE
The <fx:include> 'source' attribute.- See Also:
- Constant Field Values
-
INCLUDE_RESOURCES_ATTRIBUTE
The <fx:include> 'resources' attribute.- See Also:
- Constant Field Values
-
INCLUDE_CHARSET_ATTRIBUTE
The <fx:include> 'charset' attribute.- See Also:
- Constant Field Values
-
SCRIPT_TAG
The tag name of <fx:script>.- See Also:
- Constant Field Values
-
SCRIPT_SOURCE_ATTRIBUTE
The <fx:script> 'source' attribute.- See Also:
- Constant Field Values
-
SCRIPT_CHARSET_ATTRIBUTE
The <fx:script> 'charset' attribute.- See Also:
- Constant Field Values
-
DEFINE_TAG
The tag name of <fx:define>.- See Also:
- Constant Field Values
-
REFERENCE_TAG
The tag name of <fx:reference>.- See Also:
- Constant Field Values
-
REFERENCE_SOURCE_ATTRIBUTE
The <fx:reference> 'source' attribute.- See Also:
- Constant Field Values
-
ROOT_TAG
The tag name of <fx:root>.- Since:
- JavaFX 2.2
- See Also:
- Constant Field Values
-
ROOT_TYPE_ATTRIBUTE
The <fx:root> 'type' attribute.- Since:
- JavaFX 2.2
- See Also:
- Constant Field Values
-
COPY_TAG
The tag name of <fx:copy>.- See Also:
- Constant Field Values
-
COPY_SOURCE_ATTRIBUTE
The <fx:copy> 'source' attribute.- See Also:
- Constant Field Values
-
EVENT_HANDLER_PREFIX
The prefix of event handler attributes.- See Also:
- Constant Field Values
-
EVENT_KEY
The name of the Event object in event handler scripts.- See Also:
- Constant Field Values
-
CHANGE_EVENT_HANDLER_SUFFIX
Suffix for property change/invalidation handlers.- See Also:
- Constant Field Values
-
NULL_KEYWORD
Value that represents 'null'.- See Also:
- Constant Field Values
-
ESCAPE_PREFIX
Escape prefix for escaping special characters inside attribute values. Serves as an escape forESCAPE_PREFIX,RELATIVE_PATH_PREFIX,RESOURCE_KEY_PREFIX,EXPRESSION_PREFIX,BI_DIRECTIONAL_BINDING_PREFIX- Since:
- JavaFX 2.1
- See Also:
- Constant Field Values
-
RELATIVE_PATH_PREFIX
Prefix for relative location resolution.- See Also:
- Constant Field Values
-
RESOURCE_KEY_PREFIX
Prefix for resource resolution.- See Also:
- Constant Field Values
-
EXPRESSION_PREFIX
Prefix for (variable) expression resolution.- See Also:
- Constant Field Values
-
BINDING_EXPRESSION_PREFIX
Prefix for binding expression resolution.- See Also:
- Constant Field Values
-
BINDING_EXPRESSION_SUFFIX
Suffix for binding expression resolution.- See Also:
- Constant Field Values
-
BI_DIRECTIONAL_BINDING_PREFIX
Prefix for bidirectional-binding expression resolution.- Since:
- JavaFX 2.1
- See Also:
- Constant Field Values
-
BI_DIRECTIONAL_BINDING_SUFFIX
Suffix for bidirectional-binding expression resolution.- Since:
- JavaFX 2.1
- See Also:
- Constant Field Values
-
ARRAY_COMPONENT_DELIMITER
Delimiter for arrays as values.- Since:
- JavaFX 2.1
- See Also:
- Constant Field Values
-
LOCATION_KEY
A key for location URL in namespace map.- Since:
- JavaFX 2.2
- See Also:
getNamespace(), Constant Field Values
-
RESOURCES_KEY
A key for ResourceBundle in namespace map.- Since:
- JavaFX 2.2
- See Also:
getNamespace(), Constant Field Values
-
CONTROLLER_METHOD_PREFIX
Prefix for controller method resolution.- See Also:
- Constant Field Values
-
CONTROLLER_KEYWORD
A key for controller in namespace map.- Since:
- JavaFX 2.1
- See Also:
getNamespace(), Constant Field Values
-
CONTROLLER_SUFFIX
A suffix for controllers of included fxml files. The full key is stored in namespace map.- Since:
- JavaFX 2.2
- See Also:
getNamespace(), Constant Field Values
-
INITIALIZE_METHOD_NAME
The name of initialize method.- Since:
- JavaFX 2.2
- See Also:
- Constant Field Values
-
JAVAFX_VERSION
Contains the current javafx version.- Since:
- JavaFX 8.0
-
FX_NAMESPACE_VERSION
Contains the current fx namepsace version.- Since:
- JavaFX 8.0
- See Also:
- Constant Field Values
-
-
Constructor Details
-
FXMLLoader
public FXMLLoader()Creates a new FXMLLoader instance. -
FXMLLoader
Creates a new FXMLLoader instance.- Parameters:
location- the location used to resolve relative path attribute values- Since:
- JavaFX 2.1
-
FXMLLoader
Creates a new FXMLLoader instance.- Parameters:
location- the location used to resolve relative path attribute valuesresources- the resources used to resolve resource key attribute values- Since:
- JavaFX 2.1
-
FXMLLoader
Creates a new FXMLLoader instance.- Parameters:
location- the location used to resolve relative path attribute valuesresources- resources used to resolve resource key attribute valuesbuilderFactory- 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 valuesresources- resources used to resolve resource key attribute valuesbuilderFactory- the builder factory used by this loadercontrollerFactory- the controller factory used by this loader- Since:
- JavaFX 2.1
-
FXMLLoader
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 valuesresources- resources used to resolve resource key attribute valuesbuilderFactory- the builder factory used by this loadercontrollerFactory- the controller factory used by this loadercharset- 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 valuesresources- resources used to resolve resource key attribute valuesbuilderFactory- the builder factory used by this loadercontrollerFactory- the controller factory used by this loadercharset- the character set used by this loaderloaders- list of loaders- Since:
- JavaFX 2.1
-
-
Method Details
-
getLocation
Returns the location used to resolve relative path attribute values.- Returns:
- the location used to resolve relative path attribute values
-
setLocation
Sets the location used to resolve relative path attribute values.- Parameters:
location- the location
-
getResources
Returns the resources used to resolve resource key attribute values.- Returns:
- the resources used to resolve resource key attribute values
-
setResources
Sets the resources used to resolve resource key attribute values.- Parameters:
resources- the resources
-
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
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
-
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
Sets the controller associated with the root object. The value passed to this method is used as the value of thefx:controllerattribute. This method must be called prior to loading the document when using controller event handlers when anfx:controllerattribute is not specified in the document.- Parameters:
controller- the controller to associate with the root object- Since:
- JavaFX 2.2
-
getBuilderFactory
Returns the builder factory used by this loader.- Returns:
- the builder factory
-
setBuilderFactory
Sets the builder factory used by this loader.- Parameters:
builderFactory- the builder factory
-
getControllerFactory
Returns the controller factory used by this loader.- Returns:
- the controller factory
- Since:
- JavaFX 2.1
-
setControllerFactory
Sets the controller factory used by this loader.- Parameters:
controllerFactory- the controller factory- Since:
- JavaFX 2.1
-
getCharset
Returns the character set used by this loader.- Returns:
- the character set
-
setCharset
Sets the character set used by this loader.- Parameters:
charset- the character set- Since:
- JavaFX 2.1
-
getClassLoader
Returns the classloader used by this loader.- Returns:
- the classloader
- Since:
- JavaFX 2.1
-
setClassLoader
Sets the classloader used by this loader and clears any existing imports.- Parameters:
classLoader- the classloader- Since:
- JavaFX 2.1
-
getLoadListener
Returns this loader's load listener.- Returns:
- the load listener
- Since:
- 9
-
setLoadListener
Sets this loader's load listener.- Parameters:
loadListener- the load listener- Since:
- 9
-
load
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 tosetLocation(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
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
@Deprecated 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- the package name of the class to loadclassName- the name of the class to load- Returns:
- the class
- Throws:
ClassNotFoundException- if the specified class cannot be found
-
loadType
Deprecated.This method now delegates togetDefaultClassLoader().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
Returns the default class loader.- Returns:
- the default class loader
- Since:
- JavaFX 2.1
-
setDefaultClassLoader
Sets the default class loader.- Parameters:
defaultClassLoader- The default class loader to use when loading classes.- Since:
- JavaFX 2.1
-
load
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
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 valuesresources- 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 IOExceptionLoads 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 valuesresources- the resources used to resolve resource key attribute valuesbuilderFactory- 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 IOExceptionLoads 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 valuesresources- the resources used to resolve resource key attribute valuesbuilderFactory- the builder factory used when loading the documentcontrollerFactory- 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 IOExceptionLoads 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 valuesresources- the resources used to resolve resource key attribute valuesbuilderFactory- the builder factory used when loading the documentcontrollerFactory- the controller factory used when loading the documentcharset- 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
-
getDefaultClassLoader().