B4X Store
jdashboardUI / Core & Utilities / JDashboardThemes
Core & Utilities

JDashboardThemes

15 CSS themes with immediate runtime switching for Forms and Panes

Search all jdashboardUI docs
Source
jdashboardUI.b4xlib · Public API only
Store language: en

Core & Utilities · jdashboardUI 24.2 · B4J / JavaFX

JDashboardThemes is jdashboardUI's common-theme system. It can restyle common JavaFX controls across an entire application or only one part of the interface without requiring jdashboard_WindowsStyle.

Why JDashboardThemes matters

Immediate runtime theme switching. You can switch from Light to Dark, Nord, Dracula, Monokai, Ocean, and other themes while the application is already running. No restart, layout reload or Form recreation is required.

  • 15 bundled CSS themes ready to use.
  • Live / runtime visual switching through ApplyToForm or ApplyToPane.
  • Whole-Form theming.
  • Pane-subtree theming.
  • Preserves unrelated stylesheets and replaces only themes managed by this module.
  • Synchronizes the theme with RootPane so popup/context menus can inherit the same look.
  • Themes can be listed, resolved and validated before use.
  • No jdashboard_WindowsStyle dependency.

Important: this module targets common JavaFX controls. Ribbon and other custom components that manage their own CSS or inline styles keep their own visual system and are not automatically restyled.

Immediate switching while the app is running

This is one of the most useful features. Connect buttons, menus or a ComboBox and change the theme instantly:

Private Sub btnDark_Action
    JDashboardThemes.ApplyToForm( _
        MainForm, _
        JDashboardThemes.THEME_FLUENT_DARK)
End Sub

Private Sub btnOcean_Action
    JDashboardThemes.ApplyToForm( _
        MainForm, _
        JDashboardThemes.THEME_FLUENT_OCEAN)
End Sub

Private Sub btnMonokai_Action
    JDashboardThemes.ApplyToForm( _
        MainForm, _
        JDashboardThemes.THEME_MONOKAI)
End Sub

Each call replaces the managed stylesheet and applies it at that moment. The user sees the new theme without closing the application.

Apply the initial theme before showing the Form to avoid an unthemed first frame:

Private MainForm As Form

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main")

    If JDashboardThemes.ApplyToForm( _
        MainForm, _
        JDashboardThemes.THEME_FLUENT_FOREST) = False Then
        Log("Theme could not be applied")
    End If

    MainForm.Show
End Sub

Short names are also accepted:

JDashboardThemes.ApplyToForm(MainForm, "dark")
JDashboardThemes.ApplyToForm(MainForm, "ocean")
JDashboardThemes.ApplyToForm(MainForm, "nord")
JDashboardThemes.ApplyToForm(MainForm, "tokyo night")

The 15 bundled themes

Constant CSS file Alias
THEME_FLUENT_LIGHT fluent-light.css light / fluent-light
THEME_FLUENT_DARK fluent-dark.css dark / fluent-dark
THEME_FLUENT_OCEAN fluent-ocean.css ocean / fluent-ocean
THEME_FLUENT_FOREST fluent-forest.css forest / fluent-forest
THEME_FLUENT_LILAC fluent-lilac.css lilac / fluent-lilac
THEME_DRACULA dracula.css dracula
THEME_CATPPUCCIN_MOCHA catppuccin-mocha.css catppuccin-mocha / catppuccin mocha
THEME_NORD nord.css nord
THEME_GRUVBOX gruvbox.css gruvbox
THEME_SOLARIZED_LIGHT solarized-light.css solarized-light / solarized light
THEME_SOLARIZED_DARK solarized-dark.css solarized-dark / solarized dark
THEME_ROSE_PINE rose-pine.css rose-pine / rose pine
THEME_TOKYO_NIGHT tokyo-night.css tokyo-night / tokyo night
THEME_ONE_DARK one-dark.css one-dark / one dark
THEME_MONOKAI monokai.css monokai

The default is JDashboardThemes.DEFAULT_THEME, currently fluent-light.css.

Theme only one Pane

If JDashboardThemes.ApplyToPane( _
    pnlEditor, _
    JDashboardThemes.THEME_DRACULA) = False Then
    Log("Could not theme editor pane")
End If

For example, this can create a dark editor area inside a light window. Runtime changes are immediate here as well.

Preserves your other application CSS

ApplyToForm and ApplyToPane do not clear the full stylesheet list. They remove only URLs recognized as themes managed by JDashboardThemes.

This means you can keep:

my-application.css
+
JDashboardThemes.THEME_NORD

and replace Nord with another theme without reloading your own CSS.

PopupControls and context menus

ApplyToForm applies the theme to both Form.Stylesheets and RootPane, then calls applyCss on the tree.

This helps popup controls created from that tree — such as a native TextField context menu — have access to the same theme when they appear.

Live theme selector

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main")

    cmbTheme.Items.AddAll(JDashboardThemes.GetAvailableThemes)
    cmbTheme.SelectedIndex = 0

    JDashboardThemes.ApplyToForm(MainForm, cmbTheme.Items.Get(0))
    MainForm.Show
End Sub

Private Sub cmbTheme_SelectedIndexChanged(Index As Int, Value As Object)
    If Index < 0 Then Return

    If JDashboardThemes.ApplyToForm(MainForm, Value) = False Then
        Log("Theme was not applied: " & Value)
    End If
End Sub

The visual change happens immediately whenever the user selects another theme.

GetAvailableThemes

Dim Themes As List = JDashboardThemes.GetAvailableThemes

For Each ThemeFile As String In Themes
    Log(ThemeFile)
Next

Returns all 15 bundled CSS filenames.

ThemeExists

If JDashboardThemes.ThemeExists("rose pine") Then
    JDashboardThemes.ApplyToForm(MainForm, "rose pine")
End If

It checks both name resolution and whether the CSS asset can actually be opened from File.DirAssets.

ResolveThemeFile

Log(JDashboardThemes.ResolveThemeFile("dark"))
' fluent-dark.css

Log(JDashboardThemes.ResolveThemeFile("tokyo night"))
' tokyo-night.css

Unknown names return "". Null or an empty string resolve to the default theme.

CurrentTheme and SetCurrentTheme

If JDashboardThemes.SetCurrentTheme("gruvbox") Then
    Log(JDashboardThemes.CurrentTheme)
End If

SetCurrentTheme does not visually change an existing Form by itself. It validates and stores the theme. Use ApplyToForm or ApplyToPane for a live UI change.

Remove a managed theme

JDashboardThemes.RemoveFromForm(MainForm)
JDashboardThemes.RemoveFromPane(pnlEditor)

Only themes managed by this module are removed; external application CSS remains.

Complete public API

Method Return Purpose
ApplyToForm(TargetForm As Form, ThemeName As String) Boolean Immediately apply a theme to the Form
ApplyToPane(TargetPane As Pane, ThemeName As String) Boolean Immediately apply a theme to a Pane
SetCurrentTheme(ThemeName As String) Boolean Validate and change CurrentTheme
RemoveFromForm(TargetForm As Form) - Remove managed themes from the Form
RemoveFromPane(TargetPane As Pane) - Remove managed themes from a Pane
GetAvailableThemes List Return all 15 bundled CSS themes
ThemeExists(ThemeName As String) Boolean Validate name and asset
ResolveThemeFile(ThemeName As String) String Resolve alias or CSS filename

State and lifecycle

JDashboardThemes is a StaticCode module:

  • no Initialize is required;
  • it does not create Views;
  • no Designer Properties;
  • no events;
  • no AddToParent;
  • it exposes CurrentTheme;
  • it uses CSS files bundled in jdashboardUI assets.

Best practices

  • Apply the initial theme before Form.Show.
  • For later changes, call ApplyToForm or ApplyToPane: the change is immediate.
  • Prefer public constants when the theme is hard-coded.
  • Use GetAvailableThemes to build dynamic selectors.
  • Use ThemeExists when the name comes from preferences or external configuration.
  • Do not clear all stylesheets manually; let the module replace only its own.
  • Remember that Ribbon and other custom components may require their own theme API.