Java Applet中的TAB键

时间:2012-06-13 12:11:07

标签: java applet

我发现Java代码有两个问题,当代码作为applet运行时,用户需要按TAB键

首先在Chrome中,媒体似乎没有被发现。

在IE9中更加巧妙地按下TAB会完全失去对applet的关注。

我之前见过这些报道,但到目前为止,我的搜索并没有提出一个简洁的解决方案,如果解决方案存在,甚至可以快速回答......是吗?

作为桌面或WebStart / JNLP应用程序运行TAB运行良好,只有在applet中它才会变得混乱。

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分: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) {}
    }