Several keyboards have a Alt Gr key. On my Swedish keyboard layout, to enter the [
character I have to press Alt Gr + 8 (or Ctrl + Alt + 8).
If I were to input this character twice in a JavaFX TextField
, where the application also has a MenuBar
, the menu bar keeps the focus instead of the text field. This makes me have to press Alt or Alt Gr again to make the TextField
get focus. I'd want the TextField
to have focus after I enter any character with the Alt Gr key.
Code to reproduce problem:
public class MenuTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new VBox();
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(new Menu("_File"));
menuBar.getMenus().add(new Menu("_Test"));
TextField input = new TextField();
pane.getChildren().add(menuBar);
pane.getChildren().add(input);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Steps to reproduce:
With the TextField
having focus do:
- With your keyboard layout set to Swedish, press Alt Gr + 8 (or Ctrl + Alt + 8) twice. For other keyboard layouts, enter any character of your choice that includes the usage of the Alt Gr key.
- Press left arrow
Expected behavior: Two [
characters are inserted into the TextField
. Caret is moved one step to the left in the TextField
.
Actual behavior: Two [
characters are inserted into the TextField
. Another menu is highlighted and has focus
Question:
Why is this happening? Even Windows' basic Notepad application behaves according to my expectations here.
Is there any way I can make the actual behavior match the expected behavior?