示例#1
0
  public static void main(String[] args) throws Throwable {
    Robot robot = new Robot();
    robot.setAutoDelay(250);

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    SwingUtilities.invokeAndWait(
        new Runnable() {

          @Override
          public void run() {
            JFrame frame = new JFrame("Test");
            frame.setContentPane(createPanel(frame));
            frame.setJMenuBar(createMenuBar());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
          }
        });

    robot.waitForIdle();

    // Change the default button to
    // force a call to BasicRootPaneUI.updateDefaultButtonBindings()
    Util.hitKeys(robot, KeyEvent.VK_TAB);

    // If the bug exists, then as soon as the menu appears,
    // the VK_ENTER, VK_DOWN, VK_UP and VK_ESC will have no
    // effect.
    Util.hitMnemonics(robot, KeyEvent.VK_U);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    robot.waitForIdle();

    checkAction();

    Util.hitMnemonics(robot, KeyEvent.VK_U);
    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    robot.waitForIdle();

    checkAction();
  }