09.04.2018 Views

tornadofx-guide

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4. Basic Controls<br />

For any Pane , you can call its button() extension function to add a Button to it. You can<br />

optionally pass a text argument and a Button.() -> Unit lambda to modify its properties.<br />

This will add a Button with red text and print "Button pressed!" every time it is clicked<br />

(Figure 4.2)<br />

button("Press Me") {<br />

textFill = Color.RED<br />

action {<br />

println("Button pressed!")<br />

}<br />

}<br />

Figure 4.2<br />

Label<br />

You can call the label() extension function to add a Label to a given Pane . Optionally<br />

you can provide a text (of type String or Property ), a graphic (of type Node or<br />

ObjectProperty ) and a Label.() -> Unit lambda to modify its properties (Figure<br />

4.3).<br />

label("Lorem ipsum") {<br />

}<br />

textFill = Color.BLUE<br />

Figure 4.3<br />

TextField<br />

For any target, you can add a TextField by calling its textfield() extension function<br />

(Figure 4.4).<br />

textfield()<br />

36

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

Saved successfully!

Ooh no, something went wrong!