Bind Value in a Label

前端 未结 1 920
温柔的废话
温柔的废话 2021-01-15 06:06

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: \         


        
1条回答
  •  执念已碎
    2021-01-15 06:36

    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"));
    

    0 讨论(0)
提交回复
热议问题