JavaFX CSS - Font color in MenuItem

天涯浪子 提交于 2019-12-12 16:43:14

问题


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.



来源:https://stackoverflow.com/questions/34682448/javafx-css-font-color-in-menuitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!