Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Value in a Label

Tags:

java

bind

javafx

is it possible to bind a Double-Value from a JavaFX Slider to a Label? I would like to get something like this:

m_maxSlider = new Label("Right Slider Val: " + m_slider.getValue1());
m_maxSlider.textProperty().bind(Double.toString(m_slider.getValue1()));

Thank you for your help.

like image 887
Lukas Hieronimus Adler Avatar asked Jul 02 '26 23:07

Lukas Hieronimus Adler


1 Answers

Assuming you have a property accessor method value1Property() returning a DoubleProperty, you can do

m_maxSlider.textProperty().bind(m_slider.value1Property().asString());

If you want to format the string using a Formatting String, do something like

m_maxSlider.textProperty().bind(m_slider.value1Property().asString("Value: %.2f"));
like image 127
James_D Avatar answered Jul 05 '26 14:07

James_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!