Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jpsacha opened this issue May 24, 2014 · 3 comments

Comments

@jpsacha
Copy link
Member

jpsacha commented May 24, 2014

From galic...@gmail.com 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
Copy link
Member Author

jpsacha commented May 24, 2014

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

Labels: Milestone-Release1.0

@jpsacha
Copy link
Member Author

jpsacha commented May 24, 2014

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 added a commit that referenced this issue Jun 21, 2014
Removed imports of JavaFX classes where possible.
Type parameters need to be JavaFX types, so left them but used alises as in the rest of ScalaFX code -
see issue #14 and #142.
@rom1dep
Copy link
Contributor

rom1dep commented Apr 25, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants