简体   繁体   English

如何将 JavaFX 窗格添加到 TornadoFX 组件?

[英]How to add JavaFX Pane to TornadoFX Component?

How do I add a JavaFX Pane to a TornadoFX vbox?如何将 JavaFX 窗格添加到 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.然而,为了在屏幕上真正显示一些东西,我们想要填充这个 VBox 作为根控件。 Using theinitializer block , let's add a JavaFX Button and a Label.使用初始化块,让我们添加一个 JavaFX 按钮和一个标签。

Also take note of the tornadofx.* import.还要注意 tornadofx.* 导入。 This is important and should be present in all your TornadoFX related files.这很重要,应该出现在所有 TornadoFX 相关文件中。 The reason this is important is that some of the functionality of the framework isn't discoverable by the IDE without the import.这很重要的原因是,如果没有导入,IDE 无法发现框架的某些功能。 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. TornadoFX 提供了一种构建器语法,可以简化您的 UI 代码。 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.与创建 UI 元素并手动将它们添加到父元素的子元素列表不同,构建器允许我们将 UI 表示为分层结构,这使您能够非常轻松地可视化生成的 UI。 Note that all builders are written in lowercase, so as to not confuse them with manual instantiation of the UI element classes.请注意,所有构建器均以小写形式编写,以免将它们与 UI 元素类的手动实例化混淆。

I hope, this may helps.我希望,这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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