【问题标题】:Javafx menuitem white borderJavafx menuitem 白色边框
【发布时间】:2013-10-13 16:11:37
【问题描述】:

我正在尝试通过 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;
}

显然它与填充有关,但我真的不知道是什么......

【问题讨论】:

    标签: java css javafx-2 menuitem menubar


    【解决方案1】:

    单击 Menu 时出现的弹出窗口是 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 */
    }
    

    附:由于该论坛网站的授权,您链接的图片无法显示。

    【讨论】:

    • 优秀的答案。
    猜你喜欢
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2015-08-26
    • 1970-01-01
    相关资源
    最近更新 更多