Java Reference
In-Depth Information
...
...
},
HBox
{
spacing: 20
content: [
Rectangle {
width: 50
height: 20
fill: Color.NAVY
stroke: Color.YELLOW
},
...
...
This lays out the components horizontally in two rows, as shown in Figure 5.10.
Figure 5.10
VBox Layout of HBoxes
In JavaFX, layout can be achieved by positioning individual nodes using either
their
x
and
y
or
translateX
and
translateY
variables directly. The other way is
to use a layout container that positions nodes in a special way. In the previous
sections, we looked at the built-in layout containers for horizontal,
HBox
, and
vertical layout,
VBox
. In the next section, we will explore custom layout using a
grid. But what internal geometry is used in doing layouts?
In JavaFX, rectangular bounds are represented by the
javafx.geometry
.Rectangle2D
class. This class contains variables for
minX
,
minY
,
maxX
,
maxY
,
width
, and
height
. However, there are several geometric properties on each
node that represent different geometries. These are
boundsInLocal
,
boundsIn-
Parent
,
boundsInScene
, and
layoutbounds
. How are these related?
Bounds may change depending on a number of variables, including clips, effects,
and transformation. So the different bounding rectangles represent the bounds
for a node depending on whether some of these effects have been applied yet.
Search WWH ::
Custom Search