skip to Main Content

I created a JavaFX ComboBox with JavaFX Scene Builder 21.0.0.

enter image description here

I set the text color to white, but the text is still black.

enter image description here

Any ideas how to resolve this issue?

2

Answers


  1. Chosen as BEST ANSWER

    One possible way to resolve the issue can be adding a stylesheet to Scene Builder:

    enter image description here

    Css code might look like this:

    .combo-box .list-cell {
        -fx-text-fill: white;
    }
    .combo-box-base .arrow-button .arrow {
        -fx-background-color: white;
    }
    

  2. As mentioned by @Billie, the best approach is to declare the styling in the CSS and include in SceneBuilder. This way you precisely know what you are styling.

    Having said that, the main reason that setting -fx-text-fill on combo-box not working is, that the feature of applying text fills or colors cannot be inherited. Only Font attributes (family, size, style & weight) can be inherited from parent node. Thats why all the font settings on ComboBox are applied on the inner Label but not the -fx-text-fill.

    Text fills or colours are applied in the CSS either directly or from a pre defined variable declared at root level.

    Below is the styling in modena.css for the ComboBox inner label and arrow:

    .combo-box > .list-cell {
        -fx-background: transparent;
        -fx-background-color: transparent;
        -fx-text-fill: -fx-text-base-color;
        -fx-padding: 0.333333em 0.666667em 0.333333em 0.666667em; /* 4 8 4 8 */
    }
    .combo-box-base > .arrow-button > .arrow {
        -fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
       ...
    }
    

    If you notice the colors are set from the variables -fx-text-base-color and -fx-mark-color respectively. So you can override these variables at ComboBox level so that all its children will then use those values. (Similar to what @jewelsea mentioned in his comment).

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search