[英]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.