Views
9 months ago

tornadofx-guide

7. Layouts and Menus

7. Layouts and Menus borderpane { top = label("TOP") { useMaxWidth = true style { backgroundColor = Color.RED } } bottom = label("BOTTOM") { useMaxWidth = true style { backgroundColor = Color.BLUE } } left = label("LEFT") { useMaxWidth = true style { backgroundColor = Color.GREEN } } right = label("RIGHT") { useMaxWidth = true style { backgroundColor = Color.PURPLE } } } center = label("CENTER") { useMaxWidth = true style { backgroundColor = Color.YELLOW } } FIGURE 7.5 You will notice that the top and bottom regions take up the entire horizontal space, while left , center , and right must share the available horizontal space. But center is entitled to any extra available space (vertically and horizontally), making it ideal to hold large controls like TableView . For instance, you may vertically stack some buttons in the left region and put a TableView in the center region (Figure 7.6). 92

7. Layouts and Menus borderpane { left = vbox { button("REFRESH") button("COMMIT") } center = tableview { items = listOf( Person("Joe Thompson", 33), Person("Sam Smith", 29), Person("Nancy Reams", 41) ).observable() } } column("NAME",Person::name) column("AGE",Person::age) Figure 7.6 BorderPane is a layout you will likely want to use often because it simplifies many complex UI's. The top region is commonly used to hold a MenuBar and the bottom region often holds a status bar of some kind. You have already seen center hold the focal control such as a TableView , and left and right hold side panels with any peripheral controls (like Buttons or Toolbars) not appropriate for the MenuBar . We will learn about Menus later in this section. Form Builder TornadoFX has a helpful Form control to handle a large number of user inputs. Having several input fields to take user information is common and JavaFX does not have a built-in solution to streamline this. To remedy this, TornadoFX has a builder to declare a Form with any number of fields (Figure 7.7). 93

GUIDE
Guide
GUIDE
GUIDE
GUIDE
Guide
Guide
GUIDE
Guide
GUIDE
Guide
Guide