I have a `StringProperty` and I want to use it for...
# tornadofx
a
I have a
StringProperty
and I want to use it for a
DatePicker
which required an
ObjectProperty<LocalDate>
Is there a way to pass a converter or something to do the mapping between the properties? What's the best practice for this? I can't change the type of the
StringProperty
variable, it's a bit of a special case.
s
I had to do something like this often enough that I wrote an extension function
fun <T> StringProperty.toObjectProperty( to:(String)->T, from:(T)->String ): ObjectProperty<T>
.
💯 1
It just created a
SimpleObjectProperty<T>
and set up listeners to copy values back and forth, with conversion.
💯 1
a
@sbyrne I see, I was expecting something like this in the std lib but I guess there isn'tÙˆ for some reason. Thank you!