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

import javafx.scene.paint.Color<br />

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

class MyView : View() {<br />

}<br />

override val root = vbox {<br />

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

textFill = Color.RED<br />

action { println("Button pressed!") }<br />

}<br />

}<br />

The builder pattern becomes especially powerful when you start nesting controls into other<br />

controls. Using these builder extension functions, you can easily populate and nest multiple<br />

HBox instances into a VBox , and create UI code that is clearly structured (Figure 4.1).<br />

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

class MyView : View() {<br />

}<br />

override val root = vbox {<br />

hbox {<br />

label("First Name")<br />

textfield()<br />

}<br />

hbox {<br />

label("Last Name")<br />

textfield()<br />

}<br />

button("LOGIN") {<br />

useMaxWidth = true<br />

}<br />

}<br />

Figure 4.1<br />

Also note we will learn about TornadoFX's proprietary Form later, which will make<br />

simple input UI's like this even simpler to build.<br />

34

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

Saved successfully!

Ooh no, something went wrong!