Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6217590

Autotransfer moves focus to removed component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 7
    • 5.0
    • client-libs
    • x86
    • linux

      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

            son Oleg Sukhodolsky (Inactive)
            son Oleg Sukhodolsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: