Views
4 months ago

tornadofx-guide

7. Layouts and Menus

7. Layouts and Menus form { hbox(20) { fieldset("Left FieldSet") { hbox(20) { vbox { field("Field l1a") { textfield() } field("Field l2a") { textfield() } } vbox { field("Field l1b") { textfield() } field("Field l2b") { textfield() } } } } fieldset("Right FieldSet") { hbox(20) { vbox { field("Field r1a") { textfield() } field("Field r2a") { textfield() } } vbox { field("Field r1b") { textfield() } field("Field r2b") { textfield() } } } } } } The HBoxes are configured with a spacing of 20 pixels, using the parameter for the hbox builder. It can also be specified as hbox(spacing = 20) for clarity. Figure 7.9 GridPane If you want to micromanage the layout of your controls, the GridPane will give you plenty of that. Of course it requires more configuration and code boilerplate. Before proceeding to use a GridPane , you might want to consider using Form or other layouts that abstract layout configuration for you. 98

7. Layouts and Menus One way to use GridPane is to declare the contents of each row . For any given Node you can call its gridpaneConstraints to configure various GridPane behaviors for that Node , such as margin and columnSpan (Figure 7.10) gridpane { row { button("North") { useMaxWidth = true gridpaneConstraints { marginBottom = 10.0 columnSpan = 2 } } } row { button("West") button("East") } row { button("South") { useMaxWidth = true gridpaneConstraints { marginTop = 10.0 columnSpan = 2 } } } } Figure 7.11 Notice how there is a margin of 10.0 between each row, which was declared for the marginBottom and marginTop of the "North" and "South" buttons respectively inside their gridpaneConstraints . Alternatively, you can explicitly specify the column/row index positions for each Node rather than declaring each row of controls. This will accomplish the exact layout we built previously, but with column/row index specifications instead. It is a bit more verbose, but it 99

guide
guide
Guide
GUIDE
guide
Guide
GUIDE
guiding
The Guide
guide
Guide
guide
GUIDE
guide
GUIDE
Guide
GUIDE
GUIDE
guide
Guide
GUIDE
Guide to
guide
guide
A guide
guide
guide
Guide
GUIDE
GUIDE