标题大部分都说明了这一点。我从另一个StackOverflow答案中获取了代码,并尝试了另一个变体,该变体是DoubleBinding类的子类,但错误仍然存在。这是针对游戏的,我正在尝试制作各种健康栏。我认为这与FXMLLoader如何调用initialize方法有关,但到目前为止我还没有发现任何东西。
public void initialize() {
// ... some code
Rectangle hpBarInside = new Rectangle(100.0,10.0);
DoubleProperty healthPercent = new SimpleDoubleProperty(1);
DoubleBinding b1 = healthPercent.multiply(hpBarInside.widthProperty());
hpBarInside.widthProperty().bind(b1);
// ... some more code
}