我想将 JavaFX Label.textProperty
与 int
值绑定(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/