JDK-4893550 : REGRESSION: Focus event suppresses button push event
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-21
  • Updated: 2006-01-30
  • Resolved: 2006-01-30
Related Reports
Relates :  
Description
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) 
======================================================================

Comments
EVALUATION This issue is by design and will not be fixed. In fact, with the fix to 4368790, this will work even better. Whenever the focus is stolen from a button, it will be reset to unarmed and unpressed. This matches the behavior of native Windows.
30-01-2006

EVALUATION Name: osR10079 Date: 07/22/2003 I think this is a Swing problem. I've verified that AWT components don't have such problem. Thus I reassign the bug to classes_swing for further investigation. ###@###.### 2003-07-22 ====================================================================== Name: ibR10256 Date: 08/28/2003 The following chronological sequence explains what happens in the above ButtonTest class when the button is pressed: 1. The button is pressed and not released: BasicButtonListener.mousePressed() is called in which the focus is requested by the button (by a button.requestFocus() call) 2. The focus goes to the button, ButtonTest.focusLost() is called in which the focus is requested by the text field 3. The focus goes back to the text field, BasicButtonListener.focusLost() is called in which the button model's "armed" property is set to false 4. The button is released and DefaultButtonModel.setPressed(false) is called but an ActionEvent is NOT fired in setPressed() as in ordinary case because the button is NOT armed ###@###.### 2003-08-28 ======================================================================
28-08-2003