簡體   English   中英

JavaFX綁定帶有int值的Label

[英]JavaFX binding Label with int value

我想JavaFX的綁定Label.textPropertyint值。

我試過例如

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM