### Show Value in Thumb

Full example of showing the value of the slider while moving in the thumb (requires the JavaObject library).
The slider is defined in the layout created with the B4J Visual Designer.
In addition, the slider track color is set.
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Slider1 As Slider
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.SetFormStyle("UTILITY")
MainForm.Show
SliderTrackColorRGB(Slider1,0,0,255)
SliderBindLabel(Slider1, "%.0f")
End Sub`
' Bind a label to a slider. The label displays the slider value.
' A label is used defined in the sub routine
' Example: SliderBindLabel(Slider1, "%.1f")
`Sub SliderBindLabel(sldr As Slider, fmt As String)
Dim lblvalue As Label
lblvalue.Initialize("lblvalue")
Dim joSlider As JavaObject = sldr
Dim joLabel As JavaObject = lblvalue
' Get the valueproperty of the slider as StringBinding
Dim vp As JavaObject = joSlider.RunMethodJO("valueProperty", Null).RunMethod("asString", Array(fmt))
' Bind the slider stringbinding to the label
joLabel.RunMethodjo("textProperty", Null).runmethodjo("bind", Array(vp))
' Add the label to the slider thumb
joSlider.RunMethodJo("lookup", Array(".thumb")).RunMethodJo("getChildren", Null).RunMethod("add", Array(lblvalue))
End Sub`
' Set the color of the slider track using RGB colors, e.g. red=255,0,0, green=0,255,0,blue=0,0,255.
' Example: SliderTrackColorRGB(Slider1, 0,255,0) sets the color to green.
`Sub SliderTrackColorRGB(slr As Slider, r As Int, g As Int, b As Int)
Dim joSldr As JavaObject = slr
joSldr.RunMethodJo("lookup", Array(".track")).RunMethod("setStyle", Array($"-fx-background-color:rgb(${r},${g},${b});"$))
End Sub`

Changed: , Category: Slider, File: T6C249M1801.htm, ID: 1801