TAB键

2012-06-13 61 views
0

我看到两个问题的Java代码,希望用户按TAB键,当代码在Chrome运行作为appletTAB键

首先,貌似没有被发现的新闻。

更多nastily在IE9按TAB失去焦点的小程序完全。

我已经看到这些报道过,但我的搜索,到目前为止,如果有一个解决方案并没有提出很好地解决,甚至是一个快速的答案......不是吗?

运行作为桌面或在webstart/JNLP应用TAB效果很好,只在小程序它会导致混乱。

+1

参考java的错误http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6456655 –

+0

你的问题是在这里吗?我们是否可以确认行为,有一个解决方法,一个错误修正,一个建议哪个键可以代替? –

+0

@userunknown“到目前为止搜索没有提出一个整洁的解决方案,或者即使解决方案存在,甚至快速回答” –

回答

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) {} 
    } 
+1

在代码框之外的答案中有一点点评论有助于理解代码背后的概念。代码是什么问题的答案。 –