Game Development Reference
In-Depth Information
An
HBox
class is a
public
class that directly extends the javafx.layout.Pane super-
class, which in turn extends a javafx.layout.Region superclass. The
javafx.layout.Region superclass extends a javafx.scene.parent superclass, which in turn
extends a javafx.scene.Node superclass, which extends the java.lang.Object master-
class. As
Figure 6-4
shows (l. 11), HBox is contained in the javafx.scene.layout pack-
age, just like the StackPane class, and it uses the following class hierarchy structure:
java.lang.Object
> javafx.scene.Node
> javafx.scene.Parent
> javafx.scene.layout.Region
> javafx.scene.layout.Pane
> javafx.scene.layout.
HBox
If an HBox has a
border
or a
padding
value specified, the contents of your HBox
layout container will respect that border or padding specification. A padding value is
specified using the Insets class, which you will be using for exactly this fine-tuned UI
control bank application.
You will use the HBox class (object), along with the Pos class constant and the In-
sets class (object), to group the UI Button objects together and, later, to fine-tune their
position as a Button control bank. This HBox layout container will thus become the
Parent node (or a branch node) for the Button UI controls (or leaf nodes).
Think of an HBox object as a way to
array
children objects
horizontally
, in a row.
These could be your image assets, which would use the basic HBox constructor (with
zero spacing), or UI controls, such as buttons, arranged next to each other but spaced
apart, using one of the overloaded constructors. The simplest constructor for an HBox
object creation would use the following
empty
constructor method call format:
HBox()
The overloaded constructor that you will be employing for your HBox object cre-
ation will use a spacing value to put some space between the child Button objects in-
side the HBox, with the following constructor method call format:
HBox(double
spacing
)
There are also two other overloaded constructor method call formats. These will al-
low you to specify the children Node objects (in this case, Button objects) inside the
constructor method call itself, as follows: