[英]Is there a way to create custom ListCells using fxml file in tornadofx?
有沒有辦法使用 tornadofx 中的 fxml 文件創建 ListView 的自定義 ListCells?
我有一個 fxml 文件CustomListCell
:
<HBox>
<Label text="File name"/>
<ImageView fitHeight="18.0" fitWidth="18.0" pickOnBounds="true"/>
<stylesheets>
...
</stylesheets>
</HBox>
我有這個 fxml 的CustomListCell.kt
。 我想做這樣的事情:
val customList = ListView<CustomListCell>()
customList.add(CustomListCell(name, image))
如何為此目的實現CustomListCell.kt
?
我不知道為什么你認為在這里使用 fxml 是一個好主意,但是通過這個例子你可以得到你正在尋找的結果:
class Example: View("Example") {
val listofitem = FXCollections.observableArrayList<TextImagen>()
override val root = vbox {
listofitem.add(TextImagen("Car","car.png"))
listofitem.add(TextImagen("Apple","apple.png"))
listofitem.add(TextImagen("Pencil","pencil.png"))
listview<TextImagen>(listofitem){
cellFormat {
graphic = cache(it){
hbox {
label(it.name)
imageview(it.url){
fitHeight = 18.0
fitWidth = 18.0
isPickOnBounds = true
}
}
}
}
}
}
}
class TextImagen(val name : String, val url : String)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.