Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6448190
Votes 0
Synopsis Focus issue with JFrame and JButton
Category java:classes_awt
Reported Against
Release Fixed 1.4.2_13(b03), 5.0u10(b02) (Bug ID:2140913) , 7(b03) (Bug ID:2141354) , 6u1(b01) (Bug ID:2141355)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 6430995 , 6435715 , 6668749
Submit Date 12-JUL-2006
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");
      }
    });
  }
}
Posted Date : 2006-07-12 20:33:04.0

revised/corrected test
Posted Date : 2006-07-12 20:35:20.0
Work Around
N/A
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.
Posted Date : 2006-07-13 11:34:02.0

perhaps we should not allow synchronous focus request if we are in processing of
pending lightweigh requests (i.e. KFM.clearingCurrentLightweightRequests is true)
Posted Date : 2006-07-19 17:37:23.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang