转载

TornadoFX大杂烩

compile 'no.tornado:tornadofx:1.7.17'
compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

HelloWorld

import javafx.application.Application
import tornadofx.*

class App:tornadofx.App(MainView::class,MainStylesheet::class)

class MainView:View() {
    override val root = vbox {
        label("Hello World")
    }
}

class MainStylesheet:Stylesheet() {
    init {
        label {
            fontSize = 20.px
        }
    }
}

fun main(args:Array<String>) {
    Application.launch(App::class.java,*args)
}

进阶之Observable

import javafx.application.Application
import javafx.collections.FXCollections
import tornadofx.*

class App:tornadofx.App(MainView::class,MainStylesheet::class)

class Person(id: Int, name: String) {
    var id: Int by property(id)
    var name: String by property(name)
}

class MainView:View() {
    private val persons = FXCollections.observableArrayList(
            Person(10, "Ant"),
            Person(20, "Bee"),
            Person(30, "Cat")
    )
    override val root = tableview(persons) {
        column("ID", Person::id)
        column("name", Person::name)
    }
}

class MainStylesheet:Stylesheet() {
    init {
        label {
            fontFamily = "Noto Sans CJK SC Medium"
            fontSize = 20.px
        }
    }
}

fun main(args:Array<String>) {
    Application.launch(App::class.java,*args)
}

注意:

  • JavaFX可能对中文支持不好,最要手动设置中g字体

文章首发: https://baijifeilong.github.io

原文  https://baijifeilong.github.io/2018/12/09/tornadofx/
正文到此结束
Loading...