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.

3. Components<br />

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

import javafx.scene.layout.BorderPane<br />

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

class MasterView: View() {<br />

val topView: TopView by inject()<br />

val bottomView: BottomView by inject()<br />

override val root = BorderPane()<br />

}<br />

init {<br />

with(root) {<br />

top = topView.root<br />

bottom = bottomView.root<br />

}<br />

}<br />

class TopView: View() {<br />

}<br />

override val root = Label("Top View")<br />

class BottomView: View() {<br />

}<br />

override val root = Label("Bottom View")<br />

Injection Using find()<br />

The inject() delegate will lazily assign a given component to a property. The first time that<br />

component is called is when it will be retrieved. Alternatively, instead of using the inject()<br />

delegate you can use the find() function to retrieve a singleton instance of a View or<br />

other components.<br />

16

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

Saved successfully!

Ooh no, something went wrong!