[英]How to add a combobox to a tableview in Kotlin using TornadoFx
列構建器的第二個類型參數不是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知識,那么它肯定是不完整的。 不過,它也不應該是不可靠的,所以請告訴我其中是否有錯誤,或者您是否有改進建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.