JavaFX CSS-MenuItem中的字体颜色 [英] JavaFX CSS - Font color in MenuItem

查看:1129
本文介绍了JavaFX CSS-MenuItem中的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用JavaFX设置MenuBar的样式,并且一直在尝试更改font-Color MenuItem中的文本,但没有成功.

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.

这是我的CSS代码.

我该怎么办?

.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;
}

推荐答案

要在CSS中设置菜单项的文本样式,您必须选择标签使用.menu-item .label{....}之类的菜单项,

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.

这篇关于JavaFX CSS-MenuItem中的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆