### Add Style Sheet dynamically to Form

To add a CSS style sheet to a form, use the stylesheets.add subroutine.
Steps
Define the style sheet, save in the files folder and add to the B4J IDE Files Manager.
Example file: styles.css
In the Subroutine AppStart, add after MainForm.Show:
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "styles.css"))
Example CSS file mymenubar.css
/*
CSS File defining a white menubar with menu text items in red
*/
.menu .label {
-fx-text-fill: red;
}
.menu-item .label {
-fx-text-fill: red;
}
.menu-bar {
-fx-background-color: white;
}
In Subroutine AppStart, add after MainForm.Show:
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "mymenubar.css"))
This also applies to any other form.
Using a JavaObject (requires JavaObject library) with same result
(just as an FYI)
Dim jo As JavaObject = MainForm.RootPane
jo.RunMethodJO("getStylesheets",Null).RunMethod("add",Array(File.GetUri(File.DirAssets, "mymenubar.css")))

Changed: 2018-06-05 13:06, Category: CSS, File: T6C177M1281.htm, ID: 1281