所以我可能在这里缺少明显的东西,但是我有一个类,该类的方法返回其实例变量的DoubleBinding:
public DoubleBinding getTotalBinding(){
DoubleProperty h = new SimpleDoubleProperty(100); //100
DoubleProperty a1 = baseValueProperty(); // Base
DoubleProperty aib = itemModifierBaseProperty(); // Item base change
DoubleProperty aip = itemModifierPercentProperty(); // Item percent change
DoubleProperty atb = titleModifierBaseProperty(); // Title base change
DoubleProperty atp = titleModifierPercentProperty(); // Title percent change
DoubleProperty abb = buffModifierBaseProperty(); // Buff base change
DoubleProperty abp = buffModifierPercentProperty(); // Buff percent change
return Bindings.createDoubleBinding(
() -> a1.add(aib.add(atb.add(abb))).multiply((h.add(aip.add(atp.add(abp)))).divide(h)).get()
);
}
现在,当我使用此绑定绑定到文本节点时:
total.textProperty().bind(Bindings.format("%.0f", attribute.getTotalBinding()));
这很好,并且只要更改任何属性,文本节点都会更新。但是,如果我尝试对另一个SimpleDoubleProperty进行类似绑定:
getSomeSimpleDoubleProperty().bind(attribute.getTotalBinding());
getSomeSimpleDoubleProperty().addListener(event -> {
System.out.println("Something changed");
});
这不起作用,并且在更改属性时不会触发侦听器。但是,如果我绑定到属性的某些随机奇异属性:
getSomeSimpleDoubleProperty().bind(attribute.itemModifierBaseProperty());
可以更新。因此,总绑定在Bindings.format()中使用时有效,而不仅仅是.bind()。有人可以向我解释为什么它无法正常工作并找到解决方案吗?谢谢!
答案 0 :(得分:0)
通过在DoubleBinding构造函数中添加相关性来解决此问题。
sed -i "" "s/search/high-replace/g" *.txt