Views
6 months ago

tornadofx-guide

7. Layouts and Menus

7. Layouts and Menus hbox { button("Button 1") { hboxConstraints { marginRight = 20.0 hGrow = Priority.ALWAYS } } button("Button 2") } You can use a shorthand extension property for hGrow without calling hboxConstraints() . hbox { button("Button 1") { hGrow = Priority.ALWAYS } button("Button 2") } FlowPane The FlowPane lays out controls left-to-right and wraps to the next line on the boundary. For example, say you added 100 buttons to a FlowPane (Figure 7.3). You will notice it simply lays out buttons from left-to-right, and when it runs out of room it moves to the "next line". flowpane { for (i in 1..100) { button(i.toString()) { setOnAction { println("You pressed button $i") } } } } Figure 7.3 90

7. Layouts and Menus Notice also when you resize the window, the FlowLayout will re-wrap the buttons so they all can fit (Figure 7.4) Figure 7.4 The FlowLayout is not used often because it is often simplistic for handling a large number of controls, but it comes in handy for certain situations and can be used inside other layouts. BorderPane The BorderPane is a highly useful layout that divides controls into 5 regions: top , left , bottom , right , and center . Many UI's can easily be built using two or more of these regions to hold controls (Figure 7.5). 91

GUIDE
GUIDE
GUIDE
GUIDE
Guide
GUIDE
Guide
GUIDE
Guide
GUIDE
GUIDE
GUIDE
Guide
Guide
The Ultimate Guide The Ultimate Guide