VoiceOver Uses Mouse to Activate JButtons in German

XMLWordPrintable

    • os_x

      In VoiceOver you can press CTRL + ALT + SPACE to click the button that has the VoiceOver cursor.

      Normally this is supposed to work by triggering a JButton's AccessibleAction. But as a fallback VoiceOver may instead temporarily move the mouse over to the center of the button, click, and then move the mouse back.

      If the JRE Locale is set to German (and probably other languages): VoiceOver uses the mouse-positioning fallback instead of using the AccessibleAction.

      The expected behavior is to use the AccessibleAction and to not move the mouse.

      Sample code:

      ```
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.MouseListener;
      import java.util.Locale;

      /**
       * Steps to reproduce:
       * 1. Open this program
       * 2. Turn on VoiceOver
       * 3. Navigate the VoiceOver cursor to "Sample Button"
       * 4. Press CTRL + ALT + SPACE to activate "Sample Button"
       *
       * If the test passes: then the computer should been and
       * an ActionEvent should be printed to the console.
       *
       * Otherwise the button was not activated.
       */
      public class VoiceOverButtonTest extends JPanel {
          public static void main(String[] args) {
              // to reproduce this bug, use german ("de-DE")
              Locale.setDefault(Locale.forLanguageTag("de-DE"));

              // to NOT reproduce this bug, use English ("en-US")
      // Locale.setDefault(Locale.forLanguageTag("en-US"));

              SwingUtilities.invokeLater(() -> {
                  VoiceOverButtonTest t = new VoiceOverButtonTest();
                  JFrame frame = new JFrame("VoiceOverButtonTest");
                  frame.getContentPane().add(t);
                  frame.pack();
                  frame.setVisible(true);
              });
          }

          public VoiceOverButtonTest() {
              JButton button = new JButton("Sample Button");

              // If VoiceOver can't (or won't) use AccessibleActions, then it's
              // fallback plan is to quickly move the mouse to the button, click it,
              // and then return the mouse to its starting position. So we need
              // to remove MouseListeners from the button to confirm that VoiceOver
              // is triggering the button using the AccessibleAction or not.
              for (MouseListener mouseListener : button.getMouseListeners()) {
                  button.removeMouseListener(mouseListener);
              }

              button.addActionListener(e -> {
                  System.out.println(e);
                  Toolkit.getDefaultToolkit().beep();
              });

              setLayout(new BorderLayout());
              add(button, BorderLayout.CENTER);
          }
      }
      ```

            Assignee:
            Jeremy Wood
            Reporter:
            Jeremy Wood
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: