How can I style a JavaFX menu and its items in CSS?
.menu-bar {
-fx-background-color: black ;
-fx-opacity: 0.5;
-fx-border-width: 2.0;
}
.menu-bar .label {
-fx-font-size: 14.0 pt;
-fx-font-family: "Bookman Old Style";
-fx-text-fill: white;
-fx-font-weight: bold;
-fx-padding: 10.0px;
}
.menu-bar .menu-button:hover, .menu-bar .menu-button:focused, .menu-bar .menu-button:showing {
-fx-background: black ;
-fx-opacity: 0.5;
-fx-text-fill: white;
}
.menu-item {
-fx-padding: 0.0em 0.0em 0.0em 0.0em;
-fx-text-fill: black;
-fx-background: darkgray ;
}
.menu-item .label{
-fx-font-size: 14.0 pt;
-fx-text-fill: black;
}
.menu-item .label:hover{
-fx-font-size: 14.0 pt;
-fx-background: black ;
-fx-text-fill: white;
}
.context-menu {
-fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
-fx-background-color:white ;
-fx-border-width: 0.2px;
-fx-border-color: black;
/** -fx-background-insets: 0.0, 1.0, 2.0;
-fx-background-radius: 0.0 6.0 6.0 6.0, 0.0 5.0 5.0 5.0, 0.0 4.0 4.0 4.0;
-fx-padding: 0.333333em 0.083333em 0.666667em 0.083333em;
-fx-opacity: 0.9;*/
}
I think you forgot the -fx-skin
property in .context-menu
.
Follow the How to style menu button and menu items.