gpt4 book ai didi

java - 如何使用 TornadoFx 将组合框添加到 Kotlin 中的表格 View

转载 作者:行者123 更新时间:2023-12-01 19:57:23 31 4
gpt4 key购买 nike

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

我已经阅读了文档,但似乎很多内容都写了一半,而且不可靠。我是 JavaFx 的新手,并且正在不断学习。我学习 Kotlin 是因为我认为使用他们的 JavaFx (TornadoFx) 版本会更容易理解。

任何指导将不胜感激。

图片: enter image description here

更新

TableView 图片: enter image description here

最佳答案

列构建器的第二个类型参数不是 UI 元素类型,而是值类型,因此在您的情况下它应该是 String。下面是一个完整的示例应用程序,展示了在 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 知识,那么它绝对是不完整的。不过它不应该不可靠,所以如果其中有错误,或者您有改进的建议,请告诉我。

关于java - 如何使用 TornadoFx 将组合框添加到 Kotlin 中的表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49105742/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com