Consider the (kotlin/tornadofx) example below, which aims to connect the contents of a textfield with the text of a label through binding. The label should reflect a derived value of the textfield, in this case the hash. How do I properly achieve this binding (I feel that using a changelistener is not the proper way to go).
class HashView : View("My View") {
val hashProperty = SimpleStringProperty("EMPTY")
override val root = vbox {
textfield {
hashProperty.bind(stringBinding(text) { computeHash(text)}) // This does not work
}
label(hashProperty)
}
}
PS: answers in java / JavaFX are also welcome as long as I can somehow apply the idea in tornadofx as well.
UPDATE 1: I have discovered that there was only a minor change necessary to make my example work, namely it should be
hashProperty.bind(stringBinding(textProperty() { computeHash(this.value) })
I am however still not certain whether this is the conventional way to do it. So I'm going to leave this question open.