javafxmnemonics

Mnemonics - how to set color?


I have multiple buttons in in my javafx appliaction with mnemonics. When I press "Alt" the mnemonics appear in a dark color but I want them to be white.

What is the right css selector for this?

enter image description here

I tried:

.mnemonic-underline: {
  -fx-stroke: white;
}

But after that the underlines are visible all the time.


Solution

  • This should work:

    :show-mnemonics > .mnemonic-underline {
        -fx-stroke: white;
    }
    

    Example program:

    public class MnemonicStylingSSCCE extends Application {
    
        @Override
        public void start(Stage stage) {
            // Init label
            final Label mnemonic = new Label("_Mnemonic");
            mnemonic.setMnemonicParsing(true);
    
            // Init scene
            final Scene scene = new Scene(mnemonic);
            scene.getStylesheets().add(MnemonicStylingSSCCE.class.getResource("mnemonic.css").toExternalForm());
            stage.setScene(scene);
    
            // Request focus & show
            stage.requestFocus();
            stage.show();
        }
    
    }
    

    Side note - the content of mnemonic.css is CSS shown above (but with the red color instead of white).

    enter image description here