設(shè)置快捷鍵 需要在場景圖(Scene)里面才能設(shè)置快捷鍵
//第一種創(chuàng)建快捷鍵的方式(win10容易出問題,以前常用)
KeyCombination kc1 = new KeyCodeCombination(KeyCode.C,KeyCombination.ALT_DOWN,KeyCombination.CONTROL_DOWN);//Ctrl+Alt+C
Mnemonic mc1 = new Mnemonic(b1,kc1);//第二個(gè)參數(shù)需要
scene.addMnemonic(mc1);//需要一個(gè)Mnemonic對象,創(chuàng)建一個(gè)給他
//第二種創(chuàng)建快捷鍵的方式
KeyCombination kc2 = new KeyCharacterCombination("0",KeyCombination.ALT_DOWN);
Mnemonic mc2 = new Mnemonic(b1,kc2);
scene.addMnemonic(mc2);
//第三種創(chuàng)建快捷鍵的方式(基本不用,需要太多的按鍵了)
KeyCombination kc3 = new KeyCodeCombination(KeyCode.K,KeyCombination.SHIFT_DOWN,KeyCombination.CONTROL_DOWN,KeyCombination.ALT_DOWN,KeyCombination.META_DOWN,KeyCombination.SHORTCUT_DOWN);
Mnemonic mc3 = new Mnemonic(b1,kc3);
scene.addMnemonic(mc3);
//第四種(常用)
KeyCombination kccb = new KeyCodeCombination(KeyCode.Y,KeyCombination.SHORTCUT_DOWN);//這里括號里面可以加更多的按鍵
scene.getAccelerators().put(kccb, new Runnable() {
@Override
public void run() {
System.out.println("run()方法");
}
});