问题
As far as I understand you can define "color variables" in the css.
Let's say, I have a color called "default-background-color", and I set all backgrounds to be this color.
-default-background-color: #d0d0d0;
[...]
.button{
-fx-background-color: -default-background-color
}
Then, during runtime, I want to change this color to be something else, so that all backgrounds change to my new color.
How is this achieved without reloading a new css file?
回答1:
You can change set the style programmatically on any node to change the value of the looked-up color. The new looked-up color value will propagate to all child nodes. So, for example
root.setStyle("-default-background-color: #d0d080;");
来源:https://stackoverflow.com/questions/34696297/change-one-color-global-color-during-runtime-in-javafx