我正在尝试通过 CSS 更改 Javafx 中菜单栏和菜单项的背景颜色。我已经设法更改菜单栏和菜单的颜色,但是菜单项有一个奇怪的问题:更改背景颜色后,顶部和底部始终有白色边框。 这是我的 CSS 代码:
.menu-bar {
-fx-background-color: green;
}
.menu-bar .menu-button:hover, .menu-bar .menu-button:focused, .menu-bar .menu-button:showing {
-fx-background: -fx-accent;
-fx-background-color: darkgreen;
-fx-text-fill: -fx-selection-bar-text;
}
.menu-item {
-fx-background-color: darkgreen;
}
这是错误的图片: Image (抱歉,我无法发布图片,因为这是我的第一篇文章,我的声誉太低了......)
我发现如果我添加这些代码行,底部的边框会变大(!):
.menu-item {
-fx-background-color: darkgreen;
-fx-padding: 0em 0em 0em 0em;
}
所以显然它与填充有关,但我真的不知道是什么......
最佳答案
单击菜单时出现的弹出窗口是一个 ContextMenu
,它具有并显示 MenuItems。样式化菜单项是不够的,它们的父级/容器也应该被样式化:
.context-menu {
-fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
-fx-background-color: darkgreen;
-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 */
}
附言由于该论坛网站的授权,您链接的图片无法显示。
关于Javafx 菜单项白色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347299/