将javaFX DoubleProperty格式化为-100.00

时间:2016-04-21 16:08:46

标签: java data-binding javafx

我使用JavaFX 文字对象,我将其绑定到进度指示器

我希望它能显示完成了多少(%)的工作。

代码:

 text.textProperty().bind(indicator.progressProperty().multiply(100.00).asString("%.02f %%"));

如何将-100.00设为0.00?我只是无法弄清楚...(我使用了if else进行乘法,除法但它没有wkorking(?" ... ":" ...&#34)

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

使用

text.textProperty().bind(
    Bindings.when(indicator.progressProperty().lessThan(0))
    .then("0.00")
    .otherwise(indicator.progressProperty().multiply(100.00).asString("%.02f %%")));

text.textProperty().bind(
    Bindings.max(0, indicator.progressProperty()).multiply(100.00).asString("%.02f %%"));