问题描述
我在TornadoFX(Kotlin)中有这个TableView:
I have this TableView in TornadoFX (Kotlin):
class MainView : View() {
val persone = listOf(
Persona("marco", LocalDate.of(1980, 12, 20)),
Persona("francesca", LocalDate.of(1950, 1, 10)),
Persona("caterina", LocalDate.of(1973, 5, 3))
).observable()
var tbl: TableView<Persona> by singleAssign()
override val root = vbox(10.0)
init {
with(root) {
this.setMaxSize(300.0, 300.0)
tbl = tableview(persone) {
column("Nome", Persona::nome)
column("Data di nascita", Persona::birthday)
column("Età", Persona::eta)
selectionModel.selectionMode = SelectionMode.SINGLE
onDoubleClick {
println(this.selectedItem)
}
}
}
}
}
当我双击一行时,我看到以下结果:com.kotlin.test.Persona@581f0ad3
when I do a double click on a row, I see this result:com.kotlin.test.Persona@581f0ad3
如何获取字段的值?
推荐答案
您已经发现您获得了 Persona
类的实例,因此可以轻松使用这些字段.但是,TornadoFX具有便利功能,可以处理TableRow上的双击:
You have already discovered that you got an instance of your Persona
class, so the fields are readily available to you. However, TornadoFX has a convenience function to handle double click on a TableRow:
onUserSelect { persona ->
println(persona.nome)
}
onUserSelect
函数采用一个可选参数来配置要响应的点击次数,默认值为2,因此它可以用作双击回调.
The onUserSelect
function takes an optional parameter to configure how many clicks to react on, default is 2, so it works as a double click callback.
这篇关于TornadoFX TableView:获取选定的行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!