2017-09-24 70 views
0

VBox中有兩個按鈕。如果點擊第一個按鈕,然後按「TAB」,對焦框將移動到第二個按鈕。所以我的問題是,如果我想爲其他功能使用「TAB」,我如何更改或取消或阻止JavaFX中的「TAB」的默認功能?JavaFX如何更改快捷鍵的默認功能?

Button btn1 = new Button("First Button"); 
Button btn2 = new Button("Second Button"); 
VBox root = new VBox(); 
root.getChildren().addAll(btn1,btn2); 

回答

0

您需要使用setOnKeyPressed/Released/Typed方法之一。然後做你的魔力。例如只消費它,以防止按鈕之間的切換。

btn1.setOnKeyPressed(e->{ 
     if (e.getCode() == KeyCode.TAB) { 
      e.consume(); 
     } 
    });