2016-07-29 85 views
1

所以我有一个很奇怪的小问题。我设计了我的未修饰应用程序的菜单和菜单栏。如果我将菜单项悬停在上下文菜单中,菜单会将其背景颜色更改为默认的一个窗口。Java FX菜单背景颜色错误?

图片的场景(第二张图片,我徘徊在“模型”菜单项): Here I am hovering a menu which is doing its job.

If I hover one of my menu items, the menu it's background jumps to blue.

If I am not standing on the menu item with my mouse, the menu item will also have a blue background.

有谁知道如何解决的蓝色背景?我想让菜单具有像第一张图片一样的悬停背景。菜单项也应该有它自己的背景,如果我不用鼠标就可以跳到蓝色。

CSS:

.menu-bar { 
    -fx-background-color: transparent; 
} 
.menu { 
    -fx-label-padding: 3px; 
} 
.menu .label, .menu-item .label { 
    -fx-text-fill: #eee; 
} 
.menu:hover, .menu:focused, .menu:pressed { 
    -fx-background-color: rgba(0, 0, 0, 0.2); 
} 
.menu-item:hover { 
    -fx-background-color: rgba(0, 0, 0, 0.4); 
} 
.context-menu { 
    -fx-background-color: rgba(0, 0, 0, 0.3); 
} 

预先感谢您。

回答

3

添加到您的CSS

.menu-item:focused { 
    -fx-background-color : <preferred color>; 
} 
+0

我不知道我是如何错过的,谢谢。 – Displee

1

您要添加的属性的冗余层.menumenu-item。只尝试照顾相关属性。例如在你的情况下,menu需要遵循你的着色模式,当hoveredshowing事件。 所以加

.menu:hover, .menu:showing{ 
    -fx-background-color: <preferred backgound>; 
} 

同样只focused属性添加到menu-item,因为剩下的这股context-menu backgound

.menu-item:focused{ 
    -fx-background-color: <preferred background>; 
} 

看看这个简单的演示的快照:

enter image description here