I use this css-script which i include over setStyle
:
checkBox.setStyle("" +
".check-box:selected > .box {\n" +
" /* background color for selected checkbox */\n" +
" -fx-background-color: lime;\n" +
"}\n" +
"\n" +
".check-box > .box {\n" +
" /* background color of unselected checkbox */\n" +
" -fx-background-color: red;\n" +
"}\n" +
"\n" +
".check-box:selected > .box > .mark,\n" +
".check-box:indeterminate > .box > .mark {\n" +
" /* modify mark color */\n" +
" -fx-background-color: blue;\n" +
"}");
But it doesn't work....
I use Java 9
Thanks for your help
This won't work. The style
property can only contain property assignments, not selectors.
You could assign those colors using a combination of a stylesheet and the style
property though by using looked-up colors (only works for colors though):
.check-box {
/* default properties */
selected-box-color: black;
box-color: black;
mark-color: white;
}
.check-box:selected > .box {
/* background color for selected checkbox */
-fx-background-color: selected-box-color;
}
.check-box > .box {
/* background color of unselected checkbox */
-fx-background-color: box-color;
}
.check-box:selected > .box > .mark,
.check-box:indeterminate > .box > .mark {
/* modify mark color */
-fx-background-color: mark-color;
}
// overwrite colors from stylesheet
checkBox.setStyle("selected-box-color: lime; box-color: red; mark-color: blue;");