Java Reference
In-Depth Information
F IGURE 14.24
The HBox places the nodes in one row and the VBox places the nodes in one
column.
The program defines the getHBox() method. This method returns an HBox that contains
two buttons and an image view (lines 30-39). The background color of the HBox is set to gold
using Java CSS (line 33). The program defines the getVBox() method. This method returns
a VBox that contains five labels (lines 41-55). The first label is added to the VBox in line 44
and the other four are added in line 51. The setMargin method is used to set a node's margin
when placed inside the VBox (line 50).
14.22
How do you add a node to a Pane , StackPane , FlowPane , GridPane , BorderPane ,
HBox , and VBox ? How do you remove a node from these panes?
Check
Point
14.23
How do you set the alignment to right for nodes in a FlowPane , GridPane , HBox ,
and VBox ?
14.24
How do you set the horizontal gap and vertical hap between nodes in 8 pixels in a
FlowPane and GridPane and set spacing in 8 pixels in an HBox and VBox ?
14.25
How do you get the column and row index of a node in a GridPane ? How do you
reposition a node in a GridPane ?
14.26
What are the differences between a FlowPane and an HBox or a VBox ?
14.11 Shapes
JavaFX provides many shape classes for drawing texts, lines, circles, rectangles,
ellipses, arcs, polygons, and polylines.
Key
Point
The Shape class is the abstract base class that defines the common properties for all shapes.
Among them are the fill , stroke , and strokeWidth properties. The fill property speci-
fies a color that fills the interior of a shape. The stroke property specifies a color that is used
to draw the outline of a shape. The strokeWidth property specifies the width of the outline
of a shape. This section introduces the classes Text , Line , Rectangle , Circle , Ellipse ,
Arc , Polygon , and Polyline for drawing texts and simple shapes. All these are subclasses
of Shape , as shown in Figure 14.25.
VideoNote
Use shapes
14.11.1 Text
The Text class defines a node that displays a string at a starting point ( x , y ), as shown in
Figure 14.27a. A Text object is usually placed in a pane. The pane's upper-left corner point
is ( 0 , 0 ) and the bottom-right point is ( pane.getWidth() , pane.getHeight() ). A string
may be displayed in multiple lines separated by \n . The UML diagram for the Text class is
shown in Figure 14.26. Listing 14.13 gives an example that demonstrates text, as shown in
Figure 14.27b.
 
 
 
Search WWH ::




Custom Search