4

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?

Simon Forsberg
  • 13,086
  • 10
  • 64
  • 108
  • I you are using Ubuntu it could be related to this bug in Unity: https://bugs.launchpad.net/compiz-core/+bug/1233458 – Frederik H Mar 04 '16 at 10:24
  • @FrederikH Unfortunately I am using Windows, but I could try to see what happens with different OS. Thanks for the link though. – Simon Forsberg Mar 04 '16 at 12:20

0 Answers0