如何将DoubleProperty绑定到表达式?

时间:2013-10-06 22:39:38

标签: data-binding properties javafx-2 javafx

我有一个DoubleProperty(price),我希望第二个DoubleProperty(discountedPrice)绑定到price - 25%

所以我认为我会使用multiply方法,但它似乎没有按预期工作:

DoubleProperty price = new SimpleDoubleProperty();
DoubleProperty pctDiscount = new SimpleDoubleProperty();
pctDiscount.bind(price.multiply(0.75));

price.set(100);

System.out.println(pctDiscount);

我期待程序输出75,但输出是:

  

DoubleProperty [bound,invalid]

1 个答案:

答案 0 :(得分:4)

DoubleProperty是一个包装类。获得实际价值

System.out.println(pctDiscount.getValue());

System.out.println(pctDiscount.get());