JDK-4526071 : REGRESSION: MousePressed and MouseReleased events not being sent to modal dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-11-12
  • Updated: 2001-12-21
  • Resolved: 2001-12-21
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 11/12/2001


java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

I found this problem when I wanted to verify the text in a field once the field
loses focus. If the text was invalid then I would bring up a modal dialog with
an OK and Help button. I found that if the field loses focus by way of a mouse
click then the modal dialog does not respond to mouse clicks, the buttons do
nothing, but it does respond to the space bar. If the field loses focus by
pressing the tab key then the modal dialog responds to the mouse.This is only
occuring on Windows platforms, could not reproduce on Soalris.

In my test program, I can see that the button is getting mouseEntered and
mouseClicked events, but not mousePressed or mouseReleased when the problem
occurs. This program will create a frame with two text fields. When focus
leaves the first one, a modal dialog with a button appears. First use tab to
change focus between fields to bring up the modal dialog and verify you can use
the mouse to click on the button and dismiss the dialog. Next, use the mouse to
click in the fields to bring up the dialog. Now the dialog should not be
responding to mouse clicks until you click some where on the desktop, so that
the dialog loses focus.

Test Program:
import java.awt.*;
import java.awt.event.*;

public class ModalBug extends Frame
                       implements FocusListener,
                                  MouseListener,
                                  WindowListener
{

    TextField bugField1;
    TextField bugField2;
    Panel bugPanel;
    Button bugButton;
    Dialog bugDialog;

    public void windowOpened(WindowEvent e){}
    public void windowClosed(WindowEvent e){}
    public void windowIconified(WindowEvent e){}
    public void windowDeiconified(WindowEvent e){}
    public void windowDeactivated(WindowEvent e){}
    public void windowActivated (WindowEvent e){}
    public void windowClosing (WindowEvent e)
    {
        System.out.println("window closing");
        Window tmp = (Window)e.getSource();
        tmp.dispose();
    }

    public void mouseClicked(MouseEvent e){System.out.println("mouse clicked");}
    public void mousePressed(MouseEvent e){System.out.println("mouse pressed");}
    public void mouseReleased(MouseEvent e)
    {
        System.out.println("mouse released");
        bugDialog.dispose();
    }
    public void mouseEntered(MouseEvent e) {System.out.println("mouse
entered");}
    public void mouseExited(MouseEvent e){System.out.println("mouse exited");}

    public void focusGained(FocusEvent e){}
    public void focusLost(FocusEvent e)
    {
        bugDialog = new Dialog(this, true);
        bugButton = new Button();
        bugButton.addMouseListener(this);
        bugDialog.add(bugButton);
        bugDialog.setSize(50,50);
        bugDialog.addWindowListener(this);

        Point oldLoc = bugDialog.getLocation();
        if (oldLoc.x == 0 && oldLoc.y == 0)
        {
            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension size = bugDialog.getSize();

            int x = (screen.width  - size.width)/2;
            if (x < 0)
               x = 0;
            int y =  (screen.height - size.height)/2;
            if (y < 0)
               y = 0;

            bugDialog.setLocation(x, y);
        }
        bugDialog.setVisible (true);
    }


    public ModalBug()
    {
        super();
        bugPanel = new Panel();
        bugField1 = new TextField();
        bugField1.addFocusListener(this);
        bugField2 = new TextField();
        bugPanel.add(bugField1);
        bugPanel.add(bugField2);
        this.add(bugPanel);
        this.setSize(100,100);
        this.addWindowListener(this);

        Point oldLoc = getLocation();
        if (oldLoc.x == 0 && oldLoc.y == 0)
        {
            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension size = this.getSize();

            int x = (screen.width  - size.width)/2;
            if (x < 0)
               x = 0;
            int y =  (screen.height - size.height)/2;
            if (y < 0)
               y = 0;

            setLocation(x, y);
        }
        this.setVisible(true);
    }
    public static void main(String args[])
    {
        ModalBug myTest = new ModalBug();
    }
}

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

(Review ID: 134792) 
======================================================================

Comments
EVALUATION Commit to fix in Tiger (regression). ###@###.### 2001-11-13 Name: rpR10076 Date: 11/16/2001 commit to hopper and tiger ====================================================================== Here is the evaluation from the responsible engineer, ###@###.### The problem is as follows: after focus rearchitecture we post SequencedEvents as wrapper for all Focus- and WindowEvents. When we change focus in testcase native code sends two SequencedEvents for FOCUS_LOST and FOCUS_GAINED (SE1 and SE2). When we receive SE1 we call EventQueue.dispatchEvent() for FOCUS_LOST. In FOCUS_LOST handler user shows modal dialog (on the same thread) and we start secondary event pump. In this pump we receive SE2 and try to dispatch it. But SE2 can not be dispatched until SE1 will be completely dispatched. Thus we have a hang. ###@###.### 2001-11-29 Name: osR10079 Date: 12/21/2001 The same problem as in 4531693. Close as duplicate. ###@###.### 21 Dec 2001 ====================================================================== A brief note of explanation may be helpful here. This bug was filed against 1.3.1. The AWT and Swing focus architecture was completely redone in 1.4. Therefore, a fix for this bug in a 1.3.1 update release may be quite different than a fix in the 1.4-based line. This bug is planned to be fixed in 1.4.2. ###@###.### 2002-08-20
20-08-2002