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

If you need to handle a great deal of complex concurrency, you may consider using<br />

RxKotlin with RxKotlinFX. Rx also has the ability to handle rapid user inputs and<br />

events, and kill previous requests to only chase after the latest.<br />

Fragment<br />

Any View you create is a singleton, which means you typically use it in only one place at a<br />

time. The reason for this is that the root node of the View can only have a single parent in a<br />

JavaFX application. If you assign it another parent, it will disappear from its previous parent.<br />

However, if you would like to create a piece of UI that is short-lived or can be used in<br />

multiple places, consider using a Fragment . A Fragment is a special type of View<br />

designed to have multiple instances. They are particularly useful for popups or as pieces of<br />

a larger UI (such as ListCells, which we look at via the ListCellFragment later).<br />

Both View and Fragment support openModal() , openWindow() , and openInternalWindow()<br />

functions that will open the root node in a separate Window.<br />

import javafx.stage.StageStyle<br />

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

class MyView : View() {<br />

override val root = vbox {<br />

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

action {<br />

find(MyFragment::class).openModal(stageStyle = StageStyle.UTILITY)<br />

}<br />

}<br />

}<br />

}<br />

class MyFragment: Fragment() {<br />

}<br />

override val root = label("This is a popup")<br />

You can also pass optional arguments to openModal() to modify a few of its behaviors<br />

Optional Arguments for openModal()<br />

22

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

Saved successfully!

Ooh no, something went wrong!