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

1.4 REGRESSION: default button does not work reliably for javax.swing.JButton

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs



      Name: gm110360 Date: 05/30/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


      Linux lin1 2.2.16 #5 Tue Jan 29 21:24:43 CET 2002 i586
      unknown
      SuSE Linux 7.0
      libc-2.1.3-141





      A DESCRIPTION OF THE PROBLEM :
      The default button functionality does not work reliably. If
      I have got a container containing only a JButton instance
      all works satisfactoryly. If I add a add a JTextArea
      instance to the south of the container all works still
      satisfactoryly. But if I add a add the JTextArea instance to
      the north of the container instead of to the south the
      default button functionality does not work any more. A
      workaround is given by reacting on the windowActivated event
      of the related WindowListener.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the attached source code
      2. Call the program by inputting >java TestDefaultButton 1
         This will display the container with fitted out only
      with a JButton instance. Push the <Return> key: The
      Window disappears.
      3. Call the program by inputting >java TestDefaultButton 2
         This will display the container with fitted
      out addtionally with a JTextArea instance at
      south of container. Push the <Return> key: The
      Window disappears.
      4. Call the program by inputting >java TestDefaultButton 3
         This will display the container with fitted
      out addtionally with a JTextArea instance at
      north of the container instead of the south. Push the
      <Return> key: The Window does not disappear; a beep
      sounds.
      5. Call the program by inputting >java TestDefaultButton 4
         This will display the container with fitted
      out addtionally with a JTextArea instance at
      north of the container instead of the south. But now
      the WindowListener is active. Push the
      <Return> key: The Window disappears.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      see above 'Steps to Reproduce'


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      None; a beep sounds.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;


      public class TestDefaultButton extends JFrame implements ActionListener
      {
          private JButton button;
          
          public TestDefaultButton( String test_case )
              {
                  super( "TestDefaultButton" );
                  Container container = getContentPane();
                  container.setLayout( new BorderLayout() );
                  
                  button = new JButton( "Quit" );
                  button.addActionListener( this );
                  container.add( button, BorderLayout.CENTER );
                  getRootPane().setDefaultButton( button );

                  String text =
                      "the second line will be 40 chars long\n" +
                      "0123456789012345678901234567890123456789\n" +
                      "3\n4\n5\n6\n7\n8\n9\n10\n";
                  if( ! test_case.equals( "1" ) )
                  {
                      JTextArea text_area = new JTextArea( text );
                      text_area.setEditable( false );
                      if( test_case.equals( "2" ) )
                          container.add( text_area, BorderLayout.SOUTH );
                      else
                          container.add( text_area, BorderLayout.NORTH );
                  }
                      
                  if( test_case.equals( "4" ) )
                      addWindowListener( new WindowAdapter() {
                              public void windowActivated( WindowEvent event )
                                  { button.requestFocus(); } } );

                  pack();
                  setLocation( 200, 200 );
                  setVisible( true );
              }

          public void actionPerformed( ActionEvent event )
              {
                  setVisible( false );
                  removeAll();
                  dispose();
              }


          public static void main( String[] args )
              {
                  if( args.length != 1 )
                      System.out.println( "You must call the program as follows\n" +
                                          " 'java TestDefaultButton 1' or\n" +
                                          " 'java TestDefaultButton 2' or\n" +
                                          " 'java TestDefaultButton 3' or\n" +
                                          " 'java TestDefaultButton 4'" );
                  else
                      new TestDefaultButton( args[0] );
              }
          
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      see source code 'if( test_case.equals( "4" ) )' and
      following lines.
      The windowActivated WindowEvent of the WindowListener is
      used to request focus for the default button.

      Release Regression From : 1.3.1_03
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 147248)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: