Views
8 months ago

tornadofx-guide

4. Basic Controls You

4. Basic Controls You can create a CheckBox to quickly create a true/false state control and optionally manipulate it with a block (Figure 4.8). checkbox("Admin Mode") { } action { println(isSelected) } Figure 4.9 Notice that the action block is wrapped inside the checkbox so you can access its isSelected property. If you do not need access to the properties of the CheckBox , you can just express it like this. checkbox("Admin Mode").action { } println(isSelected) You can also provide a Property that will bind to its selection state. val booleanProperty = SimpleBooleanProperty() checkbox("Admin Mode", booleanProperty).action { } println(isSelected) ComboBox A ComboBox is a drop-down control that allows a fixed set of values to be selected from (Figure 4.10). val texasCities = FXCollections.observableArrayList("Austin", "Dallas","Midland", "San Antonio","Fort Worth") combobox { } items = texasCities Figure 4.10 38

4. Basic Controls You do not need to specify the generic type if you declare the values as an argument. val texasCities = FXCollections.observableArrayList("Austin", "Dallas","Midland","San Antonio","Fort Worth") combobox(values = texasCities) You can also specify a Property to be bound to the selected value. val texasCities = FXCollections.observableArrayList("Austin", "Dallas","Midland","San Antonio","Fort Worth") val selectedCity = SimpleStringProperty() combobox(selectedCity, texasCities) ToggleButton A ToggleButton is a button that expresses a true/false state depending on its selection state (Figure 4.11). togglebutton("OFF") { action { text = if (isSelected) "ON" else "OFF" } } 39

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