JavaFX CSS - Font color in MenuItem

2019-07-16 15:59发布

问题:

I am styling my MenuBar in JavaFX and I have been trying to change the font-Color of the text in the MenuItem but no success.

this is my CSS code.

How could I do it?

.menu-bar {
    -fx-background-color: darkslategray;
    -fx-opacity: 0.5;
}

.menu-bar .menu-button:hover, .menu-bar .menu-button:focused, .menu-bar .menu-button:showing {
    -fx-background: -fx-accent;
    -fx-background-color: darkslategray;
    -fx-opacity: 0.5;
    -fx-text-fill: -fx-selection-bar-text;
}



.menu-item {
    -fx-background-color: darkslategray;
    -fx-padding: 0em 0em 0em 0em;
    -fx-text-fill: greenyellow;
}


.context-menu {
    -fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
    -fx-background-color:darkslategray ;
    -fx-background-insets: 0, 1, 2;
    -fx-background-radius: 0 6 6 6, 0 5 5 5, 0 4 4 4;
    -fx-padding: 0.333333em 0.083333em 0.666667em 0.083333em; /* 4 1 8 1 */
    -fx-opacity: 0.9;
}

回答1:

To style the text of the menu-item in css, you have to select the label of the menu-item using .menu-item .label{....} like,

.menu-item .label{
    -fx-text-fill: greenyellow;
}

I hope this solved your problem.