具有 int 值的 JavaFX 绑定标签
JavaFX binding Label with int value
我想用 int
值绑定 JavaFX Label.textProperty
。
我尝试过,例如
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 Label.textProperty
。
我尝试过,例如
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());