### Set Track Color

Two example of how to set the color of the slider track.
The slider is created with the B4J Visual Designer and added to the B4J Code.
The color is set using API Methods (requires the JavaObject library).
`Sub Process_Globals
Private Slider1 As Slider
...
End Sub`
Solution B4J Code Sub Routine setSliderTrackColorName
' Set the color of the slider track by name, e.g. red, green, blue etc.
' Example: setSliderTrackColorName(Slider1, "blue")
`Sub setSliderTrackColorName(slr As Slider, color As String)
Dim joSlr As JavaObject = slr
joSlr.RunMethodJo("lookup", Array(".track")).RunMethod("setStyle", Array($"-fx-background-color:${color};"$))
End Sub`
Solution B4J Code Sub Routine setSliderTrackColorRGB
' 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: setSliderTrackColorRGB(Slider1, 0,255,0) sets the color to green.
`Sub setSliderTrackColorRGB(slr As Slider, r As Int, g As Int, b As Int)
Dim joPB As JavaObject = slr
joPB.RunMethodJo("lookup", Array(".track")).RunMethod("setStyle", Array($"-fx-background-color:rgb(${r},${g},${b});"$))
End Sub`
Solution External CSS file for all sliders
Create a file e.g. main.css with content:
/*
Set the color of the slider to red.
This settings applies to all sliders defined.
*/
.slider .track {
-fx-background-color: rgb(255,0,0);
}
Store the file in the project files folder (dirassets). Add the file main.css to the B4J IDE Files Manager.
Assign the file main.css to the form pane, like
`Private Sub Class_Globals
Private MainForm As Form
...
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "Main.css"))
Solution External CSS file for dedicated slider
Create a file e.g. main.css with content:
/*
Set the color of the slider1 to red
*/
.slider1 .track {
-fx-background-color: rgb(255,0,0);
}
Store the file in the project files folder (dirassets). Add the file main.css to the B4J IDE Files Manager.
Assign the file main.css to the form pane, like
`Private Sub Class_Globals
Private MainForm As Form
...
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "Main.css"))
Slider1.StyleClasses.Add("slider1")
``

Changed: , Category: Slider, File: T6C249M1800.htm, ID: 1800