What is the “mnemonicParsing” attribute in Java FX

旧巷老猫 提交于 2019-12-04 17:43:10

问题


I have been working with SceneBuilder and I observe that it applies the attribute of mnemonicParsing and equates it to false for every Node that I make.

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


回答1:


This refers to the Labeled.mnemonicParsing property. 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.

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.

This doesn't happen, if mnemnonicParsing is false. In this case the _ will also be printed "normally" instead of underlineing the following letter.



来源:https://stackoverflow.com/questions/36847934/what-is-the-mnemonicparsing-attribute-in-java-fx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!