Views
5 months ago

tornadofx-guide

4. Basic Controls A more

4. Basic Controls A more idiomatic way to control the button text would be to use a StringBinding bound to the textProperty: togglebutton { val stateText = selectedProperty().stringBinding { if (it == true) "ON" else "OFF" } textProperty().bind(stateText) } Figure 4.11 You can optionally pass a ToggleGroup to the togglebutton() function. This will ensure all ToggleButton s in that ToggleGroup can only have one in a selected state at a time (Figure 4.12). import javafx.scene.control.ToggleGroup import tornadofx.* class MyView : View() { private val toggleGroup = ToggleGroup() } override val root = hbox { togglebutton("YES", toggleGroup) togglebutton("NO", toggleGroup) togglebutton("MAYBE", toggleGroup) } Figure 4.12 RadioButton A RadioButton has the same functionality as a ToggleButton but with a different visual style. When it is selected, it "fills" in a circular control (Figure 4.13). 40

4. Basic Controls radiobutton("Power User Mode") { action { println("Power User Mode: $isSelected") } } Figure 4.13 Also like the ToggleButton , you can set a RadioButton to be included in a ToggleGroup so that only one item in that group can be selected at a time (Figure 4.14). import javafx.scene.control.ToggleGroup import tornadofx.* class MyView : View() { private val toggleGroup = ToggleGroup() } override val root = vbox { radiobutton("Employee", toggleGroup) radiobutton("Contractor", toggleGroup) radiobutton("Intern", toggleGroup) } Figure 4.14 DatePicker The DatePicker allows you to choose a date from a popout calendar control. You can optionally provide a block to manipulate it (Figure 4.15). datepicker { } value = LocalDate.now() Figure 4.15 41

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