Michael Langhammer
Michael Langhammer

Reputation: 730

How to style Accelerator display text in JavaFX ContextMenu via CSS?

This CSS code changes the text color of the whole text of a MenuItem:

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

The thing is that I only want to change the Accelerator display text. The CSS reference of JavaFX was not very helpful: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#contextmenu

So how can you set the style of the Accelerator display text in a ContextMenu using CSS?

Upvotes: 1

Views: 671

Answers (2)

fabian
fabian

Reputation: 82461

I inspected the skin and found out the accelerator-text class is assigned to the Label that displays the accelerator, which means you can use

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

to style the Label displaying the accelerator.

Upvotes: 3

7twenty7
7twenty7

Reputation: 568

I just gave a menuItem an id

fxml:

<MenuItem id="menuItem" mnemonicParsing="false" text="Close" accelerator="Shortcut+C"/>

and tried:

css:

#menuItem>Label {

    -fx-background-color: #0093ff;
    -fx-text-fill: #ffff00;
}

and it worked.

Upvotes: 1

Related Questions