2

I am styling my MenuBar in JavaFX and I have been trying to change the font-Color of the text in the MenuItem but no success.

this is my CSS code.

How could I do it?

.menu-bar {
    -fx-background-color: darkslategray;
    -fx-opacity: 0.5;
}

.menu-bar .menu-button:hover, .menu-bar .menu-button:focused, .menu-bar .menu-button:showing {
    -fx-background: -fx-accent;
    -fx-background-color: darkslategray;
    -fx-opacity: 0.5;
    -fx-text-fill: -fx-selection-bar-text;
}



.menu-item {
    -fx-background-color: darkslategray;
    -fx-padding: 0em 0em 0em 0em;
    -fx-text-fill: greenyellow;
}


.context-menu {
    -fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
    -fx-background-color:darkslategray ;
    -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 */
    -fx-opacity: 0.9;
}
Abdul Saleem
  • 10,098
  • 5
  • 45
  • 45
Subhi Samara
  • 77
  • 1
  • 2
  • 11
  • Possible duplicate of [How to style menu button and menu items](https://stackoverflow.com/questions/12299162/how-to-style-menu-button-and-menu-items) – Markus Weninger Jul 28 '17 at 12:53

1 Answers1

4

To style the text of the menu-item in css, you have to select the label of the menu-item using .menu-item .label{....} like,

.menu-item .label{
    -fx-text-fill: greenyellow;
}

I hope this solved your problem.

Collins Abitekaniza
  • 4,496
  • 2
  • 28
  • 43
  • 2
    An incredible useful resource, when it comes to figuring out which class needs to be changed is this overview: http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html – hotzst Jan 09 '16 at 08:50