How to set Accelerator (keyboard shortcut) for Button in javafx -


how set on mnemonic parsing in same letter.in project set mnemonic in button, button settext change in every event action,but mnemonic same in _o short keys working 1 event.how solve problem

import javafx.application.application; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.stackpane; import javafx.stage.stage;  /**  *  * @author user  */ public class javafxapplication4 extends application {     boolean b = false;     @override     public void start(stage primarystage) {      button btn = new button();     btn.settext("hell_o");     btn.setonaction(new eventhandler<actionevent>() {          @override         public void handle(actionevent event) {            b = !b;            if(!b){               btn.settext("hell_o");                system.out.println("hello");            } else {                btn.settext("w_orld");                system.out.println("world");            }         }     });      stackpane root = new stackpane();     root.getchildren().add(btn);      scene scene = new scene(root, 300, 250);      primarystage.settitle("hello world!");     primarystage.setscene(scene);     primarystage.show();     }      /**      * @param args command line arguments      */     public static void main(string[] args) {     launch(args);     }  } 

sorry english

you need switch off mnemonic parsing before text change, , after change switch on again. method settext() not implement refreshing mnemonic seems done in scene.

public class javafxapplication4 extends application {    boolean b = false;    @override   public void start(stage primarystage) {      button btn = new button();     btn.setmnemonicparsing(true);     btn.settext("hell_o");     btn.setonaction(new eventhandler<actionevent>() {        @override       public void handle(actionevent event) {         b = !b;         btn.setmnemonicparsing(false);         if (!b) {           btn.settext("hell_o");           system.out.println("hello");         } else {           btn.settext("w_orld");           system.out.println("world");         }         btn.setmnemonicparsing(true);       }     });      stackpane root = new stackpane();     root.getchildren().add(btn);      scene scene = new scene(root, 300, 250);      primarystage.settitle("hello world!");     primarystage.setscene(scene);     primarystage.show();   }    /**    * @param args command line arguments    */   public static void main(string[] args) {     launch(args);   } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -