edvin
08/21/2017, 8:55 AMPerson
object has a parent
property which is also of of type Person
. To create a column for the parent name, we
have several options. Our first attempt is simply extracting the name property manually:
column<Person, String>("Parent name", { it.value.parentProperty.value.nameProperty })
While this works, it has one major drawback. If the parent changes, the list won't be updated. We can partially remedy this
by defining the value for the property as the parent itself, and formatting it's name:
column("Parent name", Person::parentProperty).cellFormat {
textProperty().bind(it.parentProperty.value.nameProperty)
}
It might still not update right away, even though it would eventually become consistent as the TableView refreshes.
To create a binding that would reflect a change to the parent property immediately, consider using a select binding:
column<Person, String>("Parent name", { it.value.parentProperty.select(Person::nameProperty) })