MohOuss
MohOuss

Reputation: 81

How to change the color of menu control in javafx?

in an another question I find this possibilty with css

.menu .label
{
    -fx-text-fill: black;
}

but it doesn't work with the setStyle method menu.setStyle("-fx-text-fill: black");

Upvotes: 0

Views: 3112

Answers (1)

rli
rli

Reputation: 1885

The CSS applies the style to each Label below a Menu.

Whereas menu.setStyle(...) will apply only to the menu itself. And the menu itself does not have a -fx-text-fill property.

If you change your CSS to:

.menu
{
     -fx-text-fill: blue;
}

then it will be the same as your code ... and also stop to show the menu in color.

Menus don't support setting their font color like this. The CSS solution relies on an implementation detail.

If you don't want to do that you must use menu.setGraphic(...) to set a node, e.g:

    Menu menuFile = new Menu("");  
    Label t = new Label("File");
    t.setStyle("-fx-text-fill: blue;");
    menuFile.setGraphic(t);

Upvotes: 2

Related Questions