2013-10-13 188 views
0

我想通過CSS在Javafx中更改我的菜單欄和菜單項的背景顏色。我已經設法改變菜單欄和菜單的顏色,但菜單項存在一個奇怪的問題:改變背景顏色後,頂部和底部總是有白色邊框。 這是我的CSS代碼:Javafx menuitem白色邊框

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

因此很明顯,它是與填充,但我不真的不知道...

回答

2

彈出菜單上的菜單是一個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 */ 
} 

P.S.由於該論壇網站的授權,您鏈接的圖片無法顯示。

+0

非常感謝你,工作完美! – mathiasj