具有 int 值的 JavaFX 绑定(bind)标签

标签 java binding javafx

我想将 JavaFX Label.textPropertyint 值绑定(bind)。

我试过,例如

Label.textProperty().bindBidirectional(new SimpleIntegerProperty(myInt), 
                                                      new NumberStringConverter());

Label().textProperty().bindBidirectional(new SimpleIntegerProperty(myInt), 
                                                              new DecimalFormat());

但我总是得到NullPointerException

我该如何解决?

最佳答案

如果你有一个 int 你可以从它创建一个 SimpleIntegerProperty 然后在它上面使用 asString() :

label.textProperty().bind(new SimpleIntegerProperty(integer).asString());

如果你有一个IntegerProperty,你可以直接使用它

label.textProperty().bind(integerProperty.asString());

关于具有 int 值的 JavaFX 绑定(bind)标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146167/

相关文章:

java - 用鼠标拖动对象

java - 莫基托 : Testing void methods gives InvalidUseOfMatchersException

java或c库读取svn authz文件

c# - Ninject - 自动绑定(bind)从通用基类继承的程序集中的所有类(后者又实现通用接口(interface))

mvvm - View 中的 MouseDoubleClick 事件

列上的 WPF DataGrid 绑定(bind)

java - 如何在 Java 中取消转义 HTML 字符实体?

java - Android Java语音识别只需要1个结果......如何获得1个结果?

java - 在应用程序中多次打开同一个窗口(在本例中为 JavaFx)

java - Swing 和 javafx