JDK-6511554 : one more problem with focus auto transfer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2007-01-10
  • Updated: 2007-10-31
  • Resolved: 2007-10-31
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.
JDK 7
7Resolved
Related Reports
Relates :  
Relates :  
Description
in mustang we have (partially) fixed problem autotransfer after explicit focus request.
It was a very simple fix: we check if there are pending focus requests and if there are we do
not perform auto focus transfer.  However this introduce another problem: suppose we have some
pending focus requests and do not perform focus transfer, but those requests fails and so
focus stuck on the component (which was removed/hidden/disabled).  Interesting that if I make the component unfocusable, everything works fine (I suspect because of restoreFocus procedure)
Here is a test which reproduce the problem (it is a simplified one, so it is not enought to fix just this particular test)

====== the test =========
import java.awt.AWTEvent;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;

import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class failed_transfer_test {
    public static void main(String[] args) {
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                public void eventDispatched(AWTEvent e) {
                    System.out.println(e);
                }
            }, AWTEvent.FOCUS_EVENT_MASK);
        Frame frame = new Frame("test");
        frame.setLayout(new GridLayout(3, 1));
        frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    we.getWindow().dispose();
                }
            });
        final Button btn1 = new Button("press me");
        frame.add(btn1);
        final Button btn2 = new Button("I shouldn't have focus at the end");
        frame.add(btn2);
        final Button btn3 = new Button("I should have focus at the end");
        frame.add(btn3);
        btn1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    btn2.requestFocusInWindow();
                    btn2.setVisible(false);
                    // setFocusable(false) works fine however
//                     btn2.setFocusable(false);
                }
            });
        frame.pack();
        frame.setVisible(true);
    }
}

Comments
EVALUATION In fact, current behavior is considered correct. Namely, that focus is restored to the previous focus owner (not to the next, not that it disappears). So, the bugs can be closed.
31-10-2007

EVALUATION This is because of the fix for 4726458. It initiates focus-restore procedure on dispatching (by DKFM) FOCUS_GAINED on invisible/unfocusable component.
30-10-2007