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

REGRESSION: Focus event suppresses button push event

XMLWordPrintable

      Name: rmT116609 Date: 07/21/2003


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


      FULL OS VERSION :

      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If a component has focus (in this case a text field) and in response to focusLost, focus os back on it, then the event that caused the lost focus (in this case a button push) is lost. This works correctly in 1.3.1.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run program and push button. Notice that no printout indicating button push occurred appears.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should get button push event (and then perhaps regain focus on the edit field). Regardless of order, the button push event should be fired.
      ACTUAL -
      Button push is not fired, instead it is subverted by the focus event handling.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      /**
       * Title: basis<p>
       * Description: Your description<p>
       * Copyright: Copyright (c) 1999<p>
       * Company: Basis<p>
       * @author Kshanti Greene
       * @version
       */
      import javax.swing.*;
      import javax.swing.text.*;
      import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
      import java.awt.*;
      import java.awt.event.*;

      public class ButtonTest extends JFrame implements FocusListener
      {
      JButton butt;
          JTextField field;

          public ButtonTest()
          {
                  
              try
              {
                  UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
              }
              catch(Exception e){}
              
              JPanel panel = new JPanel();
              panel.setLayout(new FlowLayout());
              butt=new JButton("click");
              field=new JTextField("test");
              butt.addFocusListener(this);
              butt.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      System.err.println("action performed");
                  }
              });
              
              field.addFocusListener(this);
              panel.add(field);
              panel.add(butt);
              getContentPane().add(panel);
              setLocation(100,100);
              setSize(750,250);
              setVisible(true);
              //butt1.requestFocus();
          }
          
          public void focusGained(FocusEvent e)
          {
          }
          
          public void focusLost(FocusEvent e)
          {
              field.requestFocus();
          }
          

          public static void main(String[] args)
          {
              ButtonTest inputTest1 = new ButtonTest();
          }
          
      }

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

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

      (Incident Review ID: 191549)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: