在 tornadofx 中将组合框的项目显示为自定义节点
Show combobox's items as a custom node in tornadofx
当使用节点显示组合框项目时,仅显示 select 中的第一项。
val sspSelected = SimpleStringProperty()
val myItems = FXCollections.observableArrayList("Item 1", "Item 2","Item 3")
combobox<String>(sspSelected){
items = myItems
cellFormat {
graphic = cache{
label(it)
}
}
}
label(sspSelected)
No selected item
First item selected
Third item selected
您正在使用 cache
而未提供缓存键,因此单元格的图形节点是根据它看到的第一个值计算的。只需提供一个唯一 ID,在本例中为字符串值作为缓存键:
graphic = cache(it) {
label(it)
}
当使用节点显示组合框项目时,仅显示 select 中的第一项。
val sspSelected = SimpleStringProperty()
val myItems = FXCollections.observableArrayList("Item 1", "Item 2","Item 3")
combobox<String>(sspSelected){
items = myItems
cellFormat {
graphic = cache{
label(it)
}
}
}
label(sspSelected)
No selected item
First item selected
Third item selected
您正在使用 cache
而未提供缓存键,因此单元格的图形节点是根据它看到的第一个值计算的。只需提供一个唯一 ID,在本例中为字符串值作为缓存键:
graphic = cache(it) {
label(it)
}