Gredow
Gredow

Reputation: 120

Show combobox's items as a custom node in tornadofx

When use a node to show combobox's items only display the fisrt item I 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

Upvotes: 0

Views: 198

Answers (1)

Edvin Syse
Edvin Syse

Reputation: 7297

You are using cache without supplying a cache key, so the graphic node for the cell is calculated from the first value it sees. Simply supply a unique id, in this case the string value as a cache key:

graphic = cache(it) {
    label(it)
}

Upvotes: 1

Related Questions