JDK-6217590 : Autotransfer moves focus to removed component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2005-01-14
  • 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 :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
This problem was reported on Swing&AWT forum (see http://www.javadesktop.org/forums/thread.jspa?threadID=7672&tstart=0)
If container contains several focusable components, focus owner is in 
this container and we remove this container than autotransfer moves focus 
to next component in the container and thus focus stuck on it.
Here is a testcase:

import javax.swing.*;
import java.awt.event.*;

class AcceleratorKeyProblem {

    public static void main( String[] args ) {

        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );

        JMenuItem quit = new JMenuItem();
        quit.setAction( new AbstractAction( "Quit" ) {
            public void actionPerformed( ActionEvent _ ) {
                frame.dispose();
            }
        } );
        quit.setAccelerator( KeyStroke.getKeyStroke( "control Q" ) );
        JMenu menu = new JMenu( "File" );
        menu.add( quit );
        JMenuBar menuBar = new JMenuBar();
        menuBar.add( menu );
        frame.setJMenuBar( menuBar );

        final JPanel mainPanel = new JPanel();
        final JPanel panel1 = new JPanel();
        final JPanel panel2 = new JPanel();

        JButton b1 = new JButton( "b1" );
        JButton b2 = new JButton( new AbstractAction( "b2" ) {
            public void actionPerformed( ActionEvent _ ) {
                mainPanel.remove( panel1 );
                mainPanel.add( panel2 );
                mainPanel.revalidate();
            }
        } );

        panel1.add( b1 );
        panel1.add( b2 );

        panel2.add( new JButton( "b3" ) );

        mainPanel.add( panel1 );
        frame.getContentPane().add( mainPanel );
        frame.getRootPane().setDefaultButton( b2 );

        frame.pack();
        frame.setVisible( true );
    }
}

Steps to reproduce:
start the test, click on b2 button (it removes panel with b1 and b2 and adds
panel with b3).  After that focus will be on b1 (which was removed).

I've tested this on Linux.
###@###.### 2005-1-14 11:16:30 GMT

Comments
EVALUATION No longer reproducible after the fix for 4726458 (JDK7.0 b17).
30-10-2007

EVALUATION I reproduced it on Windows with Mustang-b34. ###@###.### 2005-05-12 11:55:07 GMT Concerns the same problem as 6180261, 6247376. ###@###.### 2005-06-22 14:55:56 GMT
12-05-2005