Reputation: 113
I want to bind JavaFX Label.textProperty
with int
value.
I tried e.g.
Label.textProperty().bindBidirectional(new SimpleIntegerProperty(myInt),
new NumberStringConverter());
or
Label().textProperty().bindBidirectional(new SimpleIntegerProperty(myInt),
new DecimalFormat());
But I always get NullPointerException.
How can I fix it?
Upvotes: 11
Views: 24703
Reputation: 36782
If you have an int you can create a SimpleIntegerProperty from it and then use the asString()
on it :
label.textProperty().bind(new SimpleIntegerProperty(integer).asString());
If you have an IntegerProperty, you can directly use it
label.textProperty().bind(integerProperty.asString());
Upvotes: 22