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 />

You can create a CheckBox to quickly create a true/false state control and optionally<br />

manipulate it with a block (Figure 4.8).<br />

checkbox("Admin Mode") {<br />

}<br />

action { println(isSelected) }<br />

Figure 4.9<br />

Notice that the action block is wrapped inside the checkbox so you can access its<br />

isSelected property. If you do not need access to the properties of the CheckBox , you can<br />

just express it like this.<br />

checkbox("Admin Mode").action {<br />

}<br />

println(isSelected)<br />

You can also provide a Property that will bind to its selection state.<br />

val booleanProperty = SimpleBooleanProperty()<br />

checkbox("Admin Mode", booleanProperty).action {<br />

}<br />

println(isSelected)<br />

ComboBox<br />

A ComboBox is a drop-down control that allows a fixed set of values to be selected from<br />

(Figure 4.10).<br />

val texasCities = FXCollections.observableArrayList("Austin",<br />

"Dallas","Midland", "San Antonio","Fort Worth")<br />

combobox {<br />

}<br />

items = texasCities<br />

Figure 4.10<br />

38

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

Saved successfully!

Ooh no, something went wrong!