Javafx button to listen to events

Still thank Aimls about javafx tutorial

https://www.bilibili.com/video/av32477066

code show as below:

 1         KeyCombination kc1 = new KeyCodeCombination(KeyCode.ENTER,KeyCombination.CONTROL_DOWN);//快捷键:ctrl+enter,第一种
 2         KeyCombination kc2 = new KeyCharacterCombination("ENTER",KeyCombination.CONTROL_DOWN);//快捷键:ctrl+enter,第二种
 3         Mnemonic mc1= new Mnemonic(btn_send,kc1);
 4         scene.addMnemonic(mc1);
 5         
 6         KeyCombination kc3 = new KeyCodeCombination(KeyCode.ENTER,KeyCombination.SHIFT_DOWN);//快捷键:ctrl+enter,第三种
 7         scene.getAccelerators().put(kc3, new Runnable(){
 8             public void RUN () {
 . 9                  // button event 
10              }
 11          });

Wherein binding shortcuts, by KeyCombination (); which can have a plurality of parameters.

 

The third method is recommended to bind shortcuts. 

Guess you like

Origin www.cnblogs.com/jdr-gbl/p/12059411.html