简体   繁体   中英

How to add JavaFX Pane to TornadoFX Component?

How do I add a JavaFX Pane to a TornadoFX vbox? All I get is a blank window.

class TradingButtons : View() {
    override val root = vbox {
        ChartTest()
    }
}


class ChartTest(vararg children: Node?) : Pane(*children) {

    init {

        val xAxis = CategoryAxis()
        val yAxis = NumberAxis(1.0, 21.0, 0.1)

        val lineChart = LineChart(xAxis, yAxis)
        this.children.add(lineChart)
    }
}

As per the documentation :

However, to actually show something on screen we want to populate this VBox acting as the root control. Using theinitializer block , let's add a JavaFX Button and a Label.

Also take note of the tornadofx.* import. This is important and should be present in all your TornadoFX related files. The reason this is important is that some of the functionality of the framework isn't discoverable by the IDE without the import. This import enabled some advanced extension functions that you really don't want to live without :)

import tornadofx.*

class MyView: View() {
    override val root = vbox {
        button("Press me")
        label("Waiting")
    }
}

TornadoFX provides a builder syntax that will streamline your UI code. Instead of creating UI elements and manually adding them to the parent element's children list, the builders allow us to express the UI as a hierarchical structure which enables you to visualize the resulting UI very easily. Note that all builders are written in lowercase, so as to not confuse them with manual instantiation of the UI element classes.

I hope, this may helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM