I would like to bidirectionaly bind a color property with r, g, b fields and also a ColorPicker. Here is what I have:
private IntegerProperty r = new SimpleIntegerProperty(); private IntegerProperty g = new SimpleIntegerProperty(); private IntegerProperty b = new SimpleIntegerProperty(); private ObjectProperty<Color> color = new SimpleObjectProperty<>(); ColorPicker colorPicker = new ColorPicker(); // Bind the colorPicker and 'color' colorPicker.valueProperty().bindBidirectional(color); Now I need to bind the color and split it in r, g, b. I know I can start with something like this (unidirectional):
color.bind(Bindings.createObjectBinding( () -> Color.rgb(r.get(), g.get(), b.get()), r, g, b )); But Java throws an exception A bound value cannot be set. Is there another way to do it or should I use listeners? Thank you!
r.set(128), and havecolor(and consequently the color picker) update? And if the user chooses a color in the color picker, do you wantr,g, andbto be updated? I think you would have to use at least some listeners for that.r,gandbas I can get them throughcolorbut I have special needs. Thank you I will try with a listener.