Java FX 中的“mnemonicParsing”属性是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36847934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:55:41  来源:igfitidea点击:

What is the "mnemonicParsing" attribute in Java FX

javajavafxjavafx-2fxml

提问by Tilak Maddy

I have been working with SceneBuilder and I observe that it applies the attribute of mnemonicParsingand equates it to falsefor every Nodethat I make.

我一直在使用 SceneBuilder,我观察到它应用了我制作的每个属性mnemonicParsing并将其等同于它。falseNode

What exactly is it? What difference does it make in Layout.xml?

究竟是什么?它有什么区别Layout.xml

回答by fabian

This refers to the Labeled.mnemonicParsingproperty. It registers a keyboard shortcut to activate the element (using the letter following _in the text+ Alt(Windows, don't know if it's the same key on other OS too)). E.g.

这是指Labeled.mnemonicParsing财产。它注册了键盘快捷键来激活元素(以下使用的信_text+ Alt(Windows中,不知道这是否对其他操作系统相同的密钥太))。例如

Button btn = new Button();
btn.setText("_Say 'Hello World'");
btn.setMnemonicParsing(true);
btn.setOnAction(new EventHandler<ActionEvent>() {

    @Override
    public void handle(ActionEvent event) {
        System.out.println("Hello World!");
    }
});

Will also print Hello World!, if the user presses Alt+ S.

Hello World!如果用户按下Alt+ S ,也会打印。

This doesn't happen, if mnemnonicParsingis false. In this case the _will also be printed "normally"instead of underlineing the following letter.

这不会发生,如果mnemnonicParsingfalse。在这种情况下,_也将“正常”打印,而不是在下面的字母下划线。