How to change the highlighting color in JavaFX?

17,446

Solution 1

Look at caspian.css (JavaFX 2) or modena.css (JavaFX 8)

.root {
    /* A bright blue for highlighting/accenting objects.  For example: selected
     * text; selected items in menus, lists, trees, and tables; progress bars;
     * default buttons.
     */
    -fx-accent: #0093ff;

    /* A bright blue for the focus indicator of objects. Typically used as the
     * first color in -fx-background-color for the "focused" pseudo-class. Also
     * typically used with insets of -1.4 to provide a glowing effect.
     *
     * TODO: should this be derived from -fx-accent?
     */
    -fx-focus-color: #0093ff;
}

Change these colors according to their usages.

Solution 2

I think Uluk Biy has answered it great way.

But the reality is styling using CSS does not override the -fx-focus-color: #0093ff, rather it will overlap. If you use -fx-focus-color: red , it will get mixed with default blue color and show a shade of grey like color. The css attribute -fx-accent has no issues.

Solution 3

Also you can use -fx-highlight-fill on text-area class selector.

.text-area {
    -fx-highlight-fill: green;
}
Share:
17,446
stetro
Author by

stetro

Updated on July 22, 2022

Comments

  • stetro
    stetro almost 2 years

    How to change the highlighting color in JavaFX? Usually it is blue with gradients, but I would like to have a green highlighting. I have tried the following:

    .root{
        -fx-shadow-highlight-color: #CCFF99;
    }
    

    Thanks for help!

  • stetro
    stetro over 11 years
    Thanks very much! And should i change the hover-background of ListViews manually ? Or is there a way to change them global like -fx-accent?
  • jewelsea
    jewelsea over 11 years
    ListView hover color is: -fx-cell-hover-color - it too can be found in caspian.css - here is a link to the 2.2 version