I use a toggleSwitch in JavaFX from fxControls. I can override by a CSS file this property:
.toggle-switch:selected .thumb-area {
-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -20%), derive(-fx-text-box-border, -30%)), linear-gradient(to bottom, derive(#0b99c9, 30%), #0b99c9);
-fx-background-insets: 0, 1;
}
But I would like to do it by code to change some colors in the component (for example the blue background in selected mode) but This doesn't work:
String css = ".toggle-switch:selected .thumb-area{-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -20%), derive(-fx-text-box-border, -30%)),linear-gradient(to bottom, derive(#0b99c9, 30%), #0b99c9);-fx-background-insets: 0, 1;}";
toggleSwitch.setStyle(css);
Thanks for your help.
selectedProperty()and update the style accordingly for both cases. Furthermore, to access the.thumb-areawould require a CSS lookup. Note that thesetStyle(...)method is expecting only a style rule, not a selector.setStyle()on lots of different UI elements.