Working with FXML Flashcards
What is FXM
FX Markup Language.
When using FXML, are you using a declarative approach or imperative.
Declarative.
Fill the blank: JavaFX provides FXML as a ______ for describing the layout and structuring the content of graphical user interfaces.
framework
What does the FXMLLoader class do?
The FXMLLoader class exposes public methods for translating
an FXML-based description of scene graph into its respective
in-memory object hierarchy.
▪ The FXMLLoader class reads an FXML file, validates it, and creates a
scene graph for the declared UI (it does not create a window or a
Stage!)
How does FXMLLoader work exactly? Name it’s four steps.
1: JavaFX application invokes FXMLLoader.
2: FXMLLoader parses the .fxml file and builds the scene graph.
3: FXMLLoader binds a controller to FXML, performs fields injection, and
calls controller’s initialize() method.
4: FXMLLoader builds scene graph and sends it to JavaFX application.
Describe the general four steps of working with FXML when making a UI.
- Design the UI on paper.
- Create the UI using Scene Builder
- Add UI components
- Set fx:id for each component
- Set event handlers (optional) – or set in controller - Create a Controller Java class:
- Create references for UI controls and annotate them with @FXML
- Declare event handler methods & implement the initialize() method - Use the FXMLLoader to generate the scene graph
The FXML document defines the UI components, layout, and property values. Does it define the behavior and event handlers as well?
No it doesn’t.
When using FXML to create your scene graph, how do you handle events?
You create a java Controller class to handle those events and provide behavior.
How do you connect references and objects?
1: In the FXML file (or using Scene Builder), we assign objects an “fx:id”
2: The value of the “fx:id” must be the name of a variable in the Controller class annotated with @FXML
Name the four steps in loading a scene graph from FXML.
1) Instantiate the FXMLLoader and pass to its constructor the
path and file name of the FXML document you want to load.
2) Instantiate and set the Controller to the loader.
3) Call the loader’s load() method.
4) Set the returned scene graph to the scene.