0
我想bidirectionaly一個color
屬性綁定與r
,g
,b
領域,也是一個顏色拾取。以下是我有:複雜性結合
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);
現在我需要綁定color
並在r
,g
,b
分裂。我知道我可以像這樣的東西(單向)開始:
color.bind(Bindings.createObjectBinding(
() -> Color.rgb(r.get(), g.get(), b.get()),
r, g, b
));
但Java拋出一個異常一個綁定的值不能設置。 是否有另一種方法來做到這一點或應該使用聽衆? 謝謝!
你的目標是什麼?你是否希望能夠做到,例如'r.set(128)',並且讓'顏色'(以及顏色選擇器)更新?如果用戶在顏色選擇器中選擇顏色,是否要'r','g'和'b'更新?我認爲你必須至少使用一些聽衆。 –
@James_D是的,正好。我知道有'r','g'和'b'這樣的技巧是有點矯枉過正的,因爲我可以通過'color'來獲取它們,但我有特殊需求。謝謝,我會嘗試與聽衆。 – Max