0

I cannot seem to understand the proper way to bind the ColorPicker value property to an ObjectProperty in ScalaFX. This is what I have done so far:

private val colorProp = new ObjectProperty[Color](this, "test", Color.White)

// Create color picker
val cp: ColorPicker = new ColorPicker(Color.White) {
    prefWidth = Prop.pickerWidth
}

colorProp <==> cp.value

However, I get this type error here:

[error]   (v: javafx.beans.property.Property[scalafx.scene.paint.Color])Unit <and>
[error]   (v: scalafx.beans.property.Property[scalafx.scene.paint.Color,scalafx.scene.paint.Color])Unit
[error]  cannot be applied to (scalafx.beans.property.ObjectProperty[javafx.scene.paint.Color])
[error]         colorProp <==> cp.value

I have been able to make things like StringProperty work correctly, but as soon as I try using the ObjectProperty, this problem arises. Any help would be great!

1 Answers1

0

Well turned out that I needed to use a JavaFX color instead of a ScalaFX color. This still seems odd to me, but it works! Any further explanation would be great though.

private val colorProp = new ObjectProperty[javafx.scene.paint.Color](this, "test", Color.White)
  • In order to implicitly convert between _ScalaFX_ wrappers and _JavaFX_ class instances, you need to have `import scalafx.Includes._` at the top of each source file. – Mike Allen Jun 20 '18 at 23:44
  • I actually had this imported already; however, with binding ObjectProperty objects, it seems the compiler is quite picky... – Seledrex Jun 27 '18 at 03:17