javafx绑定:文本绑定到两个属性

use*_*est 1 java javafx

我想将文本节点的text属性绑定到两个属性,如下所示:

Text income = new Text();
income.textProperty().bind(Bindings.concat(Available.income.asString()).concat(" Income for ").concat(now.getValue().getMonth().toString()));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在,当Available.income更改时,Text节点反映更新,但'now'更改时没有任何反应;

public static SimpleIntegerProperty income = new SimpleIntegerProperty
private ObjectProperty<YearMonth> now = new SimpleObjectProperty<YearMonth>(YearMonth.now());
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题,谢谢

Jam*_*s_D 5

你可以做

income.textProperty().bind(Bindings.createStringBinding(() -> 
    available.income.get() + " Income for " + now.getValue().getMonth(),
    available.income, now));
Run Code Online (Sandbox Code Playgroud)