1

Im very new to CSS since I was never working with weblanguages but for a JavaFX application I've got a css style sheet with a windows 10 UWP theme. The default style classes use the default windows grey button theme, but i also created a custom style class for colored components.

The colors are as variables in the the .root style class for the default style and are overwritten in the .colored style class for the colored style.

.root 
{
    -fill-color: #CCCCCC;
    ...
}

.colored
{
    -fill-color: #DD2867;
    ...
}

I now want to change the colored style colors at runtime. I know about Node#setStyle(String) in which i can modify the fill color with something like this:

root.setStyle("-fill-color: #FF00FF;");

but this has only an effect on the color in the .root style class and not the .colored style class.

Can you tell me a way to direcly modify a property of a style class at runtime or maybe an even better approach to use a default and a colored style?

Thanks in advance, Eleom.

1 Answer 1

1

Define another looked-up color on the root node, and use it in your .colored class:

{
    -fill-color: #CCCCCC;
    -colored-fill: #DD2867 ;
    ...
}

.colored
{
    -fill-color: -colored-fill;
    ...
}

Then you can change that color programmatically the same way:

root.setStyle("-colored-fill: ... ;");
Sign up to request clarification or add additional context in comments.

1 Comment

Tank you very much. It did exactly what I wanted it to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.