scalafx icon indicating copy to clipboard operation
scalafx copied to clipboard

ObjectProperty holding a ScalaFX wrapper cannot bind to ScalaFX control's properties

Open jpsacha opened this issue 11 years ago • 3 comments

From [email protected] on December 13, 2012 23:23:15

For instance, if an ObjectProperty has parameter type scalafx.scene.paint.Color it cannot be bound to fill property in scalafx.scene.shape.Rectangle.

You will get compilation error: error: overloaded method value <== with alternatives: (v: scalafx.beans.value.ObservableValue[_ <: javafx.scene.paint.Paint, _ <: javafx.scene.paint.Paint])Unit (v: javafx.beans.value.ObservableValue[_ <: javafx.scene.paint.Paint])Unit cannot be applied to (scalafx.beans.property.ObjectProperty[scalafx.scene.paint.Paint]) fill <== fillPaint

Example code illustrating that is here: https://github.com/jsacha/ProScalaFX/blob/master/test/src/misc/ChangeFillExample.scala (also attached)

Also, if you look at implementation of scalafx.scene.Node you can see that ObjectProperty types there, they use JavaFX types for value. https://code.google.com/p/scalafx/source/browse/src/scalafx/scene/Node.scala#65 I think this is because of the same binding problem.

Attachment: ChangeFillExample.scala

Original issue: http://code.google.com/p/scalafx/issues/detail?id=14

jpsacha avatar May 24 '14 02:05 jpsacha

From jpsacha on January 31, 2013 21:13:43

Labels: Milestone-Release1.0

jpsacha avatar May 24 '14 02:05 jpsacha

From jpsacha on March 07, 2013 19:15:55

This issue could not be easily and completely fixed without significant changes to ScalaFX code base. To make it easier to deal with it I implemented factory methods for ObjectProperty that simplify the work around (using ObjectProperty with JavaFX value type) https://code.google.com/p/scalafx/source/detail?r=bb04f99df3c7ebf13779bc7c3ce4f5f2a102da5d The work around is to use a factory method, rather than constructor. The factory method with create ObjectProperty with correct value type. When using it, do not specify type of created instance, let the Scala compiler infer it. For instance, instead of using constructor:

val fillPaint = new ObjectPropertyjfxsp.Paint

use factory method:

val fillPaint = ObjectProperty(Color.LIGHTGRAY)

Status: Accepted
Labels: -Priority-Medium -Milestone-Release1.0 Priority-Low

jpsacha avatar May 24 '14 02:05 jpsacha

Hi, sorry for digging up that old thread, I wonder if there is/was any progress on this? Or a known/recommended workaround? I tried the factory method approach, but that leaves me with NPEs, this is on 8.0.102-R11. Thanks!

rom1dep avatar Apr 25 '17 23:04 rom1dep