Here is an example from Pro ScalaFX:
package proscalafx.ch03
import scalafx.beans.property.StringProperty
object BidirectionalBindingExample extends App {
println("Constructing two StringProperty objects.")
val prop1 = new StringProperty("")
val prop2 = new StringProperty("")
println("Calling bindBidirectional (<==>).")
prop2 <==> prop1
println("prop1.isBound = " + prop1.isBound)
println("prop2.isBound = " + prop2.isBound)
println("Calling prop1.set(\"prop1 says: Hi!\")")
prop1() = "prop1 says: Hi!"
println("prop2.get returned:")
println(prop2())
println( """Calling prop2.set(prop2.get + "\nprop2 says: Bye!")""")
prop2() = prop2() + "\nprop2 says: Bye!"
println("prop1.get returned:")
println(prop1())
}
The two StringProperty
objects are supposed to be bound with each other, when one of them is updated, the other should be also updated. This isn't true here:
Constructing two StringProperty objects.
Calling bindBidirectional (<==>).
prop1.isBound = false
prop2.isBound = false
Calling prop1.set("prop1 says: Hi!")
prop2.get returned:
prop1 says: Hi!
Calling prop2.set(prop2.get + "\nprop2 says: Bye!")
prop1.get returned:
prop1 says: Hi!
prop2 says: Bye!