2

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 @imports 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?

josh2112
  • 829
  • 6
  • 22
  • I don't think the scope of the named color variables should be affected by if it is inline in a file or in an imported file: You might want to [file an issue in the JavaFX tracker](https://javafx-jira.kenai.com). – jewelsea Mar 17 '15 at 19:52
  • Ok, @jewelsea, I've done so: [RT-40287](https://javafx-jira.kenai.com/browse/RT-40287). Thanks. – josh2112 Mar 17 '15 at 20:23

1 Answers1

0

The named colors are fine. My @import statement is being ignored, simple as that. If I attach Themes.css manually via code, the named colors are visible. The @import statement is not picking up the themes file and not giving me any type of error. I'll open another question for that.

josh2112
  • 829
  • 6
  • 22
  • Could you please share the link to "antoher question" you've mentioned? I'm having similar problems – Amaneusz Oct 10 '18 at 08:20
  • I haven't looked at this project in years, but digging it out of storage and looking at it it doesn't appear that I ever solved the problem -- there are no @import statements to be found :-( I think I performed the imports in code. – josh2112 Oct 11 '18 at 14:02
  • I also had to merge css files programatically via URL stream handler - thing I wanted to do in couple of hours took me almost 2 days :D – Amaneusz Oct 12 '18 at 06:38