Java Reference
In-Depth Information
14.19
✓
✓
How do you create an
Image
from a URL or a filename?
Check
14.20
Point
How do you create an
ImageView
from an
Image
, or directly from a file or a URL?
14.21
Can you set an
Image
to multiple
ImageView
? Can you display the same
ImageView
multiple times?
JavaFX provides many types of panes for automatically laying out nodes in a desired
location and size.
Key
Point
JavaFX provides many types of panes for organizing nodes in a container, as shown in
Table 14.1. You have used the layout panes
Pane
,
StackPane
, and
HBox
in the preceding
sections for containing nodes. This section introduces the panes in more details.
VideoNote
Use layout panes
T
ABLE
14.1
Panes fo
r Containing and Organizing Nodes
Class
Description
Base class for layout panes. It contains the
getChildren()
method for
returning a list of nodes in the pane.
Pane
StackPane
Places the nodes on top of each other in the center of the pane.
FlowPane
Places the nodes row-by-row horizontally or column-by-column vertically.
Places the nodes in the cells in a two-dimensional grid.
GridPane
BorderPane
Places the nodes in the top, right, bottom, left, and center regions.
HBox
Places the nodes in a single row.
VBox
Places the nodes in a single column.
You have used the
Pane
in Listing 14.4, ShowCircle.java. A
Pane
is usually used as a
canvas for displaying shapes.
Pane
is the base class for all specialized panes. You have used
a specialized pane
StackPane
in Listing 14.3, ButtonInPane.java. Nodes are placed in the
center of a
StackPane
. Each pane contains a list for holding nodes in the pane. This list is an
instance of
ObservableList
, which can be obtained using pane's
getChildren()
method.
You can use the
add(node)
method to add an element to the list, use
addAll(node1,
node2, ...)
to add a variable number of nodes to the pane.
ObservableList
getChildren()
14.10.1
FlowPane
FlowPane
arranges the nodes in the pane horizontally from left to right or vertically
from top to bottom in the order in which they were added. When one row or one column
is filled, a new row or column is started. You can specify the way the nodes are placed
horizontally or vertically using one of two constants:
Orientation.HORIZONTAL
or
Orientation.VERTICAL
. You can also specify the gap between the nodes in pixels. The
class diagram for
FlowPane
is shown in Figure 14.15.
Data fields
alignment
,
orientation
,
hgap
, and
vgap
are binding properties. Each
binding property in JavaFX has a getter method (e.g.,
getHgap()
) that returns its value, a
setter method (e.g.,
sethGap(double)
) for setting a value, and a getter method that returns
the property itself (e.g.,
hGapProperty()
). For a data field of
ObjectProperty<T>
type,
the value getter method returns a value of type
T
and the property getter method returns a
property value of type
ObjectProperty<T>
.
Search WWH ::
Custom Search