Views
5 months ago

tornadofx-guide

4. Basic Controls For

4. Basic Controls For any Pane , you can call its button() extension function to add a Button to it. You can optionally pass a text argument and a Button.() -> Unit lambda to modify its properties. This will add a Button with red text and print "Button pressed!" every time it is clicked (Figure 4.2) button("Press Me") { textFill = Color.RED action { println("Button pressed!") } } Figure 4.2 Label You can call the label() extension function to add a Label to a given Pane . Optionally you can provide a text (of type String or Property ), a graphic (of type Node or ObjectProperty ) and a Label.() -> Unit lambda to modify its properties (Figure 4.3). label("Lorem ipsum") { } textFill = Color.BLUE Figure 4.3 TextField For any target, you can add a TextField by calling its textfield() extension function (Figure 4.4). textfield() 36

4. Basic Controls Figure 4.4 You can optionally provide initial text as well as a closure to manipulate the TextField . For example, we can add a listener to its textProperty() and print its value every time it changes (Figure 4.5). textfield("Input something") { textProperty().addListener { obs, old, new -> println("You typed: " + new) } } Figure 4.6 PasswordField If you need a TextField to take sensitive information, you might want to consider a PasswordField instead. It will show anonymous characters to protect from prying eyes. You can also provide an initial password as an argument and a block to manipulate it (Figure 4.7). passwordfield("password123") { } requestFocus() Figure 4.7 CheckBox 37

GUIDE
guide
Guides
Guide
GUIDE
Guide
Guide
GUIDE
GUIDE TO
Guide
Guide
GUIDE
GUIDE
Guide
GUIDE
GUIDE
GUIDE
Guide
guide
Guide
guide
GUIDE
Guide
GUIDE
GUIDE
Guide
GUIDE
Guides
Guide
GUIDE