Change one color [global] color during runtime in javafx

半城伤御伤魂 提交于 2021-01-07 07:51:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!