Java Reference
In-Depth Information
• The FXML code is separate from the program logic that's defined in Java source code—this sep-
aration of the interface (the GUI) from the implementation (the Java code) makes it easier to
debug, modify and maintain JavaFX GUI apps.
Section 25.3 JavaFX App Window Structure
• The window in which a JavaFX app's GUI is displayed is known as the stage and is an instance
of class Stage (package javafx.stage ).
• The stage contains one scene that defines the GUI as a scene graph—a tree structure of an app's
visual elements, such as GUI controls, shapes, images, video, text and more. The scene is an in-
stance of class Scene (package javafx.scene ).
• Each visual element in the scene graph is a node—an instance of a subclass of Node (package
javafx.scene ), which defines common attributes and behaviors for all nodes in the scene graph.
• The first node in the scene graph is known as the root node.
• Nodes that have children are typically layout containers that arrange their child nodes in the
scene.
• The nodes arranged in a layout container are a combination of controls and possibly other layout
containers.
• When the user interacts with a control, it generates an event. Programs can use event handling
to specify what should happen when each user interaction occurs.
An event handler is a method that responds to a user interaction. An FXML GUI's event handlers
are defined in a controller class.
Section 25.4 Welcome App—Displaying Text and an Image
• To create an app in NetBeans, you must first create a project—a group of related files, such as
code files and images that make up an app.
•The NetBeans Projects window provides access to all of your projects. Within a project's node,
the contents are organized into folders and files.
• NetBeans creates three files for a JavaFX FXML Application project: an FXML markup file for
the GUI, a file containing the app's main class and a file containing the app's controller class.
• To open a project's FXML file in JavaFX Scene Builder, right click the FXML file in the Projects
window, then select Open .
• Layout containers help you arrange GUI components. A VBox arranges its nodes vertically from
top to bottom.
• To make a layout container the root node in a scene graph, select the layout container, then select
Scene Builder's Edit > Trim Document to Selection menu item.
•A VBox 's alignment determines the layout positioning of its children.
• The preferred size (width and height) of the scene graph's root node is used by the scene to de-
termine its window size when the app begins executing.
•You can set a Label 's text either by double clicking it and typing the text, or by selecting the La-
bel and setting its Text property in the Inspector 's Properties section.
• When adding controls to a VBox , each new control is placed below the preceding ones by default.
You can change the order by dragging the children in Scene Builder 's Hierarchy window.
• To set the image to display, select the ImageView then set its Image property in the Inspector 's
Properties section. An image's aspect ratio is the ratio of the image's width to its height.
•To specify an ImageView 's size, set its Fit Width and Fit Height properties in the Inspector 's Layout
section.
Search WWH ::




Custom Search