繁体   English   中英

有没有办法在 tornadofx 中使用 fxml 文件创建自定义 ListCells?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM