0

I'm seeing two problems with Java code which expects user to press TAB key, when the code is running as an applet

Firstly in Chrome, the press is seemingly not being detected.

More nastily in IE9 pressing TAB loses focus on the applet altogether.

I've seen these reported before but my searching so far didn't suggest a neat solution, or even a quick answer if a solution exists... does it?

Running as a desktop or WebStart/JNLP app TAB works well, only in applets does it get messy.

4

2 回答 2

3

我知道现在回答这个问题已经很晚了,但如果其他人面临同样的问题,那么希望这会有所帮助。下面的链接解决了我的问题。 http://dogfeathers.com/mark/java7issue.html

于 2012-10-22T09:48:12.673 回答
0
 public void init()
  {
      Container topParent = null;
      Container parent = this;
      // The natural thing would be to call getParent() until it returns
      //   null, but then you would be looping for a long time, since
      //   PluginEmbeddedFrame's getParent() returns itself.
      for (int k=0; k < 10; k++) {
          topParent = parent;
          parent = parent.getParent();
          if (parent == null) break;
      }

      // If topParent isn't a KeyEventDispatcher then we must be in some
      //   Plugin version that doesn't need the workaround.
      try {
          KeyEventDispatcher ked = (KeyEventDispatcher)topParent;
          KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
          // You have to remove it twice, otherwise the problem isn't fixed
          kfm.removeKeyEventDispatcher(ked);
          kfm.removeKeyEventDispatcher(ked);
      } catch (ClassCastException e) {}
    }
于 2013-09-04T15:32:47.220 回答