Java Reference
In-Depth Information
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
System.out.println( " start method is invoked " );
}
public static void main(String[] args) {
System.out.println( " launch application " );
Application.launch(args);
}
}
14.4 Panes, UI Controls, and Shapes
Panes, UI controls, and shapes are subtypes of Node .
Key
Point
When you run MyJavaFX in Listing 14.1, the window is displayed as shown in Figure 14.1.
The button is always centered in the scene and occupies the entire window no matter how
you resize it. You can fix the problem by setting the position and size properties of a button.
However, a better approach is to use container classes, called panes , for automatically laying
out the nodes in a desired location and size. You place nodes inside a pane and then place the
pane into a scene. A node is a visual component such as a shape, an image view, a UI control,
or a pane. A shape refers to a text, line, circle, ellipse, rectangle, arc, polygon, polyline, etc.
UI control refers to a label, button, check box, radio button, text field, text area, etc. A scene
can be displayed in a stage, as shown in Figure 14.3a. The relationship among Stage , Scene ,
Node , Control , and Pane is illustrated in the UML diagram, as shown in Figure  14.3b.
Note that a Scene can contain a Control or a Pane , but not a Shape or an ImageView .
A Pane can contain any subtype of Node . You can create a Scene using the constructor
Scene(Parent, width, height) or Scene(Parent) . The dimension of the scene is
automatically decided in the latter constructor. Every subclass of Node has a no-arg construc-
tor for creating a default node.
Listing 14.3 gives a program that places a button in a pane, as shown in Figure 14.4
pane
node
shape
UI control
Shapes such as Line, Circle,
Ellipse, Rectangle, Path,
Polygon, Polyline, and Text are
subclasses of Shape.
Shape
Stage
1
ImageView
For displaying an image.
1
Scene
UI controls such as Label,
TextField, Button, CheckBox,
RadioButton, and TextArea are
subclasses of Control.
Control
*
Node
FlowPane
Stage
GridPane
Parent
Scene
Parent
(Pane, Control)
BorderPane
Pane
HBox
Nodes
VBox
StackPane
(a)
(b)
F IGURE 14.3
(a) Panes are used to hold nodes. (b) Nodes can be shapes, image views, UI controls, and panes.
 
 
 
Search WWH ::




Custom Search