Jam*_*een 4 treeview kotlin tornadofx
我正在学习如何使用kotlin,并已开始使用tornadoFX。我正在尝试阅读指南,但是我无法弄清楚“具有不同类型的TreeView”的含义。似乎我应该使用星形投影,当您在通话中使用*时,我就知道。
但是,一旦我这样做,树视图就会说“不允许在函数和属性的类型参数上进行投影”
这是我的代码:
MainView类:View(“”){
override val root = treeview<*> {
root = TreeItem(Person("Departments", ""))
cellFormat {
text = when (it) {
is String -> it
is Department -> it.name
is Person -> it.name
else -> throw IllegalArgumentException("Invalid Data Type")
}
}
populate { parent ->
val value = parent.value
if (parent == root) departments
else if (value is Department) persons.filter { it.department == value.name }
else null
} }
}
Run Code Online (Sandbox Code Playgroud)
老实说,我很沮丧,我不知道我要做什么。
另外,如果任何人都可以为我提供一些学习Kotlin和tornadoFX的有用链接,将不胜感激:)
看来该指南实际上是不正确的。我使用它工作treeview<Any>:
data class Department(val name: String)
data class Person(val name: String, val department: String)
val persons = listOf(
Person("Mary Hanes", "Marketing"),
Person("Steve Folley", "Customer Service"),
Person("John Ramsy", "IT Help Desk"),
Person("Erlick Foyes", "Customer Service"),
Person("Erin James", "Marketing"),
Person("Jacob Mays", "IT Help Desk"),
Person("Larry Cable", "Customer Service")
)
val departments = persons.groupBy { Department(it.department) }
override val root = treeview<Any> {
root = TreeItem("Departments")
cellFormat {
text = when (it) {
is String -> it
is Department -> it.name
is Person -> it.name
else -> kotlin.error("Invalid value type")
}
}
populate { parent ->
val value = parent.value
when {
parent == root -> departments.keys
value is Department -> departments[value]
else -> null
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
568 次 |
| 最近记录: |