Views
2 weeks ago

tornadofx-guide

7. Layouts and Menus

7. Layouts and Menus tabpane { tab("Screen 1", VBox()) { button("Button 1") button("Button 2") } tab("Screen 2", HBox()) { tableview { items = listOf( Person(1,"Samantha Stuart",LocalDate.of(1981,12,4)), Person(2,"Tom Marks",LocalDate.of(2001,1,23)), Person(3,"Stuart Gills",LocalDate.of(1989,5,23)), Person(3,"Nicole Williams",LocalDate.of(1998,8,11)) ).observable() } } } column("ID",Person::id) column("Name", Person::name) column("Birthday", Person::birthday) column("Age",Person::age) Figure 7.13 104

7. Layouts and Menus Like many builders, the TabPane has several properties that can adjust the behavior of its tabs. For instance, you can call tabClosingPolicy to get rid of the "X" buttons on the tabs so they cannot be closed. class MyView: View() { override val root = tabpane { tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE } } tab("Screen 1", VBox()) { button("Button 1") button("Button 2") } tab("Screen 2", HBox()) { button("Button 3") button("Button 4") } Builders for Menus Creating menus can be cumbersome to build in a strictly object-oriented way. But using type-safe builders, Kotlin's functional constructs make it intuitive to declare nested menu hierarchies. MenuBar, Menu, and MenuItem It is not uncommon to use navigable menus to keep a large number of commands on a user interface organized. For instance, the top region of a BorderPane is typically where a MenuBar goes. There you can add menus and submenus easily (Figure 7.5). menubar { menu("File") { menu("Connect") { item("Facebook") item("Twitter") } item("Save") item("Quit") } menu("Edit") { item("Copy") item("Paste") } } 105

GUIDE
Guide
GUIDE
GUIDE
GUIDE
GUIDE
GUIDE
guide
GUIDE
Guide
Guide
Guide