I have taken to assigning variables to frequently-used colors in my JavaFX CSS and referencing the variables rather than the color constants:
* {
theme-backgroundDark: #335588;
}
#messageListPane {
-fx-background-color: theme-backgroundDark;
}
Now I want to take the block where I define the color variable names and move it to a separate .css file. This will allow me to swap out different .css files at runtime to change the application's theme:
Theme1.css
* {
theme-backgroundDark: #335588;
}
Main.css
@import url( "/styles/Theme1.css" );
#messageListPane {
-fx-background-color: theme-backgroundDark;
}
But when I do this JavaFX is unable to find the variables at runtime:
WARNING: Could not resolve 'theme-backgroundDark' while resolving lookups for '-fx-background-color' from rule '*#messageListPane ' in stylesheet file:/C:/xxxx/styles/Main.css
It's not a problem with the @import
statement; I have other @import
s that define class selectors and those get picked up just fine in Main.css
. It seems to have something to do with the wildcard selector * { ... }
.
So why would named color variables in a wildcard selector work in the same CSS but not when imported from another CSS?