09.04.2018 Views

tornadofx-guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4. Basic Controls<br />

A more idiomatic way to control the button text would be to use a StringBinding bound to<br />

the textProperty:<br />

togglebutton {<br />

val stateText = selectedProperty().stringBinding {<br />

if (it == true) "ON" else "OFF"<br />

}<br />

textProperty().bind(stateText)<br />

}<br />

Figure 4.11<br />

You can optionally pass a ToggleGroup to the togglebutton() function. This will ensure all<br />

ToggleButton s in that ToggleGroup can only have one in a selected state at a time (Figure<br />

4.12).<br />

import javafx.scene.control.ToggleGroup<br />

import <strong>tornadofx</strong>.*<br />

class MyView : View() {<br />

private val toggleGroup = ToggleGroup()<br />

}<br />

override val root = hbox {<br />

togglebutton("YES", toggleGroup)<br />

togglebutton("NO", toggleGroup)<br />

togglebutton("MAYBE", toggleGroup)<br />

}<br />

Figure 4.12<br />

RadioButton<br />

A RadioButton has the same functionality as a ToggleButton but with a different visual<br />

style. When it is selected, it "fills" in a circular control (Figure 4.13).<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!