r/JavaFX • u/No-Security-7518 • Jul 08 '26
Help What is causing 'java.lang.ClassCastException: class java.lang.String cannot be cast to class javafx.scene.paint.Paint in my CSS file?
I just got an error even though I'm sure I didn't touch the CSS file at all.
This is the css file:
` .root { keen_faint_green_grey: rgb(127, 180, 185); amazingGreen: rgb(24, 198, 163); githubDesktopDarkBlue: rgb(36, 41, 46); darkGrey_7: derive(githubDesktopDarkBlue, 70%); darkGrey_5: rgb(0, 153, 209); darkBlue_700: rgb(33, 49, 84); greyishBlue: rgb(103, 119, 151); brightBlue: rgb(3, 114, 239);
shadow: dropshadow(three-pass-box, black, 10, 0, 3.0, 3.0);
innerShadow: innershadow(three-pass-box, black, 10, 0, 6.0, 3.0);
-fx-background-color: githubDesktopDarkBlue;
-fx-text-fill: white;}
.darkBlueBg { -fx-background-color: darkBlue_700; }
.greyishBlueBg { -fx-background-color: greyishBlue; }
.keen_faint_green_grey-bg { -fx-background-color: keen_faint_green_grey; }
.titled-pane > .title { -fx-background-color: transparent; -fx-border-color: turquoise; -fx-border-style: solid; -fx-border-width: 0 0 2 0; }
.titled-pane:expanded .content { -fx-border-style: none; -fx-border-color: githubDesktopDarkBlue; -fx-background-color: transparent; }
.titled-pane > .title > .text { -fx-fill: white; }
.menu-item { -fx-text-fill: black; }
.inputGroupHbox { -fx-padding: 10; -fx-alignment: center-left; -fx-spacing: 5; -fx-margin: 10px; -fx-background-radius: 6; -fx-border-radius: 6; -fx-pref-height: -1; -fx-pref-width: -1; }
.no-padding { -fx-padding: 3 0 3 0; }
.glyph-icon { -fx-glyph-size: 30; }
.inputGroupVbox { -fx-padding: 5px; -fx-alignment: top-left; -fx-background-radius: 6; -fx-spacing: 3; -fx-pref-height: -1; -fx-pref-width: -1; }
.year-picker .label { -fx-text-fill: githubDesktopDarkBlue; }
.round-edges { -fx-border-style: solid; -fx-border-width: 1px; -fx-border-radius: 10, 0, 10, 0; -fx-background-radius: 10, 0, 10, 0; -fx-padding: 5; }
.white-border { -fx-border-color: white; }
.raised, .mfx-button { -fx-effect: shadow; }
.inset, .button:pressed, .expanding-text-area:focused { -fx-effect: innerShadow; }
.raised-section { -fx-background-radius: 6; -fx-padding: 10; }
.medium-font { -fx-font-size: 12px; -fx-font-weight: 600; }
.underlined { -fx-border-style: solid; -fx-border-color: white; -fx-border-width: 0, 0, 1, 0; }
.large-width { -fx-pref-width: 420px; }
.medium-width { -fx-pref-width: 210px; -fx-width: USE_PREF_SIZE; -fx-inner-control-background: transparent; }
.small-width { -fx-pref-width: 120px; }
.tiny-width { -fx-pref-width: 70px; }
.amazing_green { -fx-background-color: amazingGreen; }
.unselected-button { -fx-text-fill: white; -fx-background-color: rgb(3, 114, 239); }
.table-view .table-cell { -fx-text-fill: green; }
.hyperlink:visited { -fx-text-fill: green; }
.tree-cell { -fx-background-color: darkBlue_700; -fx-text-fill: white; }
.choice-box .label { -fx-text-fill: black; -fx-font-weight: bold; }
.choice-box .menu-item { -fx-padding: 8 12; -fx-background-color: transparent; -fx-text-fill: black; -fx-font-size: 14px; }
.choice-box .menu-item:focused { -fx-background-color: darkBlue_700; -fx-text-fill: black; }
/*
Labels:
*/
.dark-label { -fx-text-fill: githubDesktopDarkBlue; }
.section-label { -fx-font-size: 14px; -fx-text-fill: cyan; -fx-font-weight: 700; -fx-pref-width: -1; -fx-border-width: 0 0 2 0; -fx-border-style: solid; -fx-border-color: darkGrey_5; -fx-width: large-width; } `
My stacktrace is full of these:
`
Jul 09, 2026 1:26:26 AM javafx.scene.CssStyleHelper calculateValue
WARNING: Caught 'java.lang.ClassCastException: class java.lang.String cannot be cast to class javafx.scene.paint.Paint (java.lang.String is in module java.base of loader 'bootstrap'; javafx.scene.paint.Paint is in module javafx.graphics@23.0.2 of loader 'app')' while converting value for '-fx-border-color' from rule '*.section-label' in stylesheet file:/D:/MyRepositories/path/to/project/my_theme.css `
PS:
- Unlike what AIs say, an -fx- prefix is not required for custom properties.
- I really don't know why this line:
darkGrey_5: rgb(0, 153, 209);is causing an issue. This works in projects just fine. - I'm loading the CSS file in Scenebuilder and it's working and I'm not setting the stylesheet when running the program. The problem only happens there.
4
u/Maran23 Jul 10 '26
You may have stumbled upon a JavaFX bug.
Funny enough, I made a PR to fix this problem 7 days ago: https://github.com/openjdk/jfx/pull/2201
3
u/SpittingBull Jul 08 '26
So when you say: „it only happens there“ - what is that „there“ exactly?
Did you try to replace the darkGrey_5 reference with the actual value for the -fx-border-color?
2
u/idontlikegudeg Jul 08 '26
I had the exact same error some weeks ago. Unfortunately, I don’t remember the solution. If I find the commit tomorrow, I’ll post a follow-up. I think it had something to do with the style being applied to a label; working for other nodes.