Css – Javafx How To not apply a css style to Label


in my Java GUI I have about 50 labels. All of them will be formatted using CSS style. But there are 5 for which I want to change the font color using a ColorPicker like this:

Color ch = lineCommentColorPicker.getValue();
if (ch != null) {

My question. How can I avoid that the color I set using the setTextFill method will be overwritten again by CSS style rules defined for the class ".label"

.label {
    -fx-text-fill: black;
    -fx-font-weight: bold;
    -fx-font-size: 12;

Best Solution

You could remove the label style alltogether with


and apply appropriate styles. Or you could add a styleclass to the other labels except the ones you wish to colorize manually like this:

    -fx-text-fill: red;