Java Reference
In-Depth Information
Fig. 25.13
|
GridPane
filled with the
Tip Calculator
's controls.
Step 4: Right-Aligning
GridPane
Column 0's Contents
A
GridPane
column's contents are left-aligned by default. To right-align the contents of
column 0, select it by clicking the tab at the top or bottom of the column, then in the
In-
spector
's
Layout
section, set the
Halignment
(horizontal alignment) property to
RIGHT
.
Step 5: Sizing the
GridPane
Columns to Fit Their Contents
By default, Scene Builder sets each
GridPane
column's width to 100 pixels and each row's
height to 30 pixels to ensure that you can easily drag controls into the
GridPane
's cells. In
this app, we sized each column to fit its contents. To do so, select the column 0 by clicking
the tab at the top or bottom of the column, then in the
Inspector
's
Layout
section, set the
Pref Width
property to
USE_COMPUTED_SIZE
to indicate that the column's width should be
based on the widest child—the
Amount
Label
in this case. Repeat this process for column 1.
The
GridPane
should appear as shown in Fig. 25.14.
Fig. 25.14
|
GridPane
with columns sized to fit their contents.
Step 6: Sizing the
TextFields
Scene Builder sets each
TextField
's width to 200 pixels by default. You may size controls
as appropriate for each GUI you create. In this app, we do not need the
TextField
s to be
so wide, so we used the preferred width for each
TextField
, which is somewhat narrower.
When setting a property to the same value for several controls, you can select all of them
and specify the value once. To select all three
TextField
s, hold the
Ctrl
(or
Command
)
key and click each
TextField
. Then in the
Inspector
's
Layout
section, set the
Pref Width
property to
USE_COMPUTED_SIZE
. This indicates that each
TextField
should use its pre-
ferred width (as defined by JavaFX). Notice that the
GridPane
's right column resizes to
the
TextField
s' preferred widths.