如何使用 TornadoFx 将组合框添加到 Kotlin 中的表视图

How to add a combobox to a tableview in Kotlin using TornadoFx

我正在尝试使用 tornadofx 将组合框添加到表视图;我认为最接近的东西是这样的:column<AvailableRooms, ComboBox<String>>("Pets Allowed", combobox<String>(values = listOf<String>("3","5"))).

我看过文档,但是好像很多都是半写的,不靠谱。我是 JavaFx 的新手,并且正在学习。我学习 Kotlin 是因为我认为使用他们的 JavaFx (TornadoFx) 版本会更容易理解。

任何指导将不胜感激。

图片:

更新

表格视图图片:

列构建器的第二个类型参数不是 UI 元素类型,而是值类型,因此在您的情况下它应该是字符串。这是一个完整的示例应用程序,展示了如何在 TableView 中使用 ComboBox:

class Person {
    val nameProperty = SimpleStringProperty()
    var name by nameProperty

    val favoriteFruitProperty = SimpleStringProperty()
    var favoriteFruit by favoriteFruitProperty
}

class MyView : View() {
    val fruits = listOf("Apple", "Banana", "Pear")

    override val root = tableview<Person> {
        isEditable = true

        column("Name", Person::nameProperty)
        column<Person, String?>("Favorite fruit", Person::favoriteFruitProperty).useComboBox(fruits.observable())

        // Populate with test data. Don't try this at home
        asyncItems {
            listOf(Person().apply { name = "John"; favoriteFruit = "Apple" }, Person().apply { name = "Jane" })
        }
    }
}

本指南确实要求您至少了解一些 JavaFX 基础知识,因此如果您事先没有 JavaFX 知识,那么它肯定是不完整的。虽然它不应该是不可靠的,所以如果其中有错误,或者您有改进的建议,请告诉我。