[英]JavaFX binding Label with int value
我想JavaFX的绑定Label.textProperty
与int
值。
我试过例如
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.