有没有一种方法可以在tornadofx中使用fxml文件创建自定义ListCells?

是否有一种方法可以使用tornadofx中的fxml文件创建ListView的自定义ListCell?

我有一个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

k910427 回答:有没有一种方法可以在tornadofx中使用fxml文件创建自定义ListCells?

我不知道您为什么在这里使用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)
本文链接:https://www.f2er.com/2374006.html

大家都在问