简体   繁体   中英

How do you bind the ColorPicker value property to a ScalaFX ObjectProperty in ScalaFX?

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM