JDK-6448190 : Focus issue with JFrame and JButton
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2_12,5.0u6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows,windows_xp
  • CPU: x86
  • Submitted: 2006-07-12
  • Updated: 2011-02-16
  • Resolved: 2006-08-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
1.4.2_13 b03Fixed 6u1Fixed 7Fixed
Related Reports
Duplicate :  
Relates :  
Description
while running the below testcase focus and functionality are lost after
moving focus out of IE and back to the applet.

Steps to reproduce.

Click serveral(4-6) times on the Non navigable Button
move the cursor out of IE and click on another window.
In my test I used a command prompt
move cursor back into the applet and click on the Focuesed Button
and then on the Non navigable Button.
Focus should be lost on the the Focused Button
and functionality lost on both buttons.
I've run it a few times and sometimes you may need to repeat the above
a couple of times.

(edited and replaced in this description the correct test case)
NewMDIDemo.java

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;

import sun.awt.SunToolkit;


public class NewMDIDemo extends JApplet
{
  public void init()
  {
    JPanel comp = new JPanel();
    _createDummy(comp);
    getContentPane().add("Center", comp);

    Component parent = comp.getParent();
    while ( parent != null && !(parent instanceof Frame) )
    {
        parent = parent.getParent();
    }
    SunToolkit.setLWRequestStatus((Window)parent, true);
  }

  private void _createDummy(JPanel rootPanel)
  {
    rootPanel.setLayout(new BorderLayout());
    final JButton btn1 = new JButton("Non navigable Button");
    final JButton btn2 = new JButton("Focused Button");
    rootPanel.add(btn1, BorderLayout.NORTH);
    rootPanel.add(btn2);

    btn1.addFocusListener(new FocusAdapter()
    {
      public void focusGained(FocusEvent event)
      {
        try
        {
          synchronized (this)
          {
            wait(3000);
          }
        }
        catch (Exception ex)
        {
          System.out.println(ex.toString());
        }

        btn2.requestFocus();
      }
    });

    btn2.addFocusListener(new FocusAdapter()
    {
      public void focusGained(FocusEvent event)
      {
        System.out.println("btn2 focusGained");
      }
    });
  }
}
revised/corrected test

Comments
EVALUATION perhaps we should not allow synchronous focus request if we are in processing of pending lightweigh requests (i.e. KFM.clearingCurrentLightweightRequests is true)
19-07-2006

EVALUATION I'm able to reproduce the bug with Mustang-beta2 + IE + WinXP SP1. Focus is sometimes lost and after some random clicks is restored. I have also noticed an exception in Java Console: Exception in thread "AWT-EventQueue-1" java.lang.SecurityException: this KeyboardFocusManager is not installed in the current thread's context at java.awt.KeyboardFocusManager.getGlobalFocusOwner(KeyboardFocusManager.java:458) at java.awt.KeyboardFocusManager.processSynchronousLightweightTransfer(KeyboardFocusManager.java:2170) at sun.awt.windows.WComponentPeer.processSynchronousLightweightTransfer(Native Method) at sun.awt.windows.WComponentPeer.requestFocus(WComponentPeer.java:539) at java.awt.Component.requestFocusHelper(Component.java:7094) at java.awt.Component.requestFocusHelper(Component.java:7050) at java.awt.Component.requestFocus(Component.java:6870) at javax.swing.JComponent.requestFocus(JComponent.java:1461) at NewMDIDemo$1.focusGained(NewMDIDemo.java:57) at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:162) at java.awt.Component.processFocusEvent(Component.java:5868) at java.awt.Component.processEvent(Component.java:5735) at java.awt.Container.processEvent(Container.java:1984) at java.awt.Component.dispatchEventImpl(Component.java:4387) at java.awt.Container.dispatchEventImpl(Container.java:2042) at java.awt.Component.dispatchEvent(Component.java:4217) at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1828) at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:863) at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:501) at java.awt.Component.dispatchEventImpl(Component.java:4259) at java.awt.Container.dispatchEventImpl(Container.java:2042) at java.awt.Component.dispatchEvent(Component.java:4217) at java.awt.KeyboardFocusManager.processCurrentLightweightRequests(KeyboardFocusManager.java:2545) at java.awt.KeyboardFocusManager.retargetFocusEvent(KeyboardFocusManager.java:2791) at java.awt.Component.dispatchEventImpl(Component.java:4252) at java.awt.Container.dispatchEventImpl(Container.java:2042) at java.awt.Component.dispatchEvent(Component.java:4217) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) I'm not sure if it is related to focus troubles as this exception occured after focus-related problems.
13-07-2006