JDK-4256692 : Showing a non modal dialog after a modal dialog allows both to receive events
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-07-23
  • Updated: 2005-05-04
  • Resolved: 2005-05-03
Related Reports
Duplicate :  
Description
Name: skT88420			Date: 07/23/99


Modal dialog does not block input to non-modal dialog if the modal dialog is shown first.

The following code:
- Creates 2 independent frames and shows 
- Creates a non modal dialog and kicks off a thread to show the dialog in 10 seconds time.
- Creates a modal dialog and shows it

Note that mouse events are printed to the console when the mouse is moved over either of the dialogs. This is wrong, a modal dialog should block all input to non-child windows in the same AppContext.


import java.awt.*;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;

public class DialogBug implements Runnable {

    Frame modalParentFrame, nonModalParentFrame;
    Dialog modalDialog, nonModalDialog;

    public DialogBug() {
        // create an independent top level frame to be the
        // parent of the modal dialog and show it
        modalParentFrame = new Frame("Parent of modal dialog");
        modalParentFrame.setBounds(100,100, 200, 200);        
        modalParentFrame.addMouseMotionListener(new DebugAdapter() );
        modalParentFrame.setVisible(true);

        // create an independent top level frame to be the
        // parent of the non-modal dialog and show it
        nonModalParentFrame = new Frame("Parent of non-modal dialog");
        nonModalParentFrame.setBounds(400,100 , 200, 200);
        nonModalParentFrame.addMouseMotionListener(new DebugAdapter() );
        nonModalParentFrame.setVisible(true);

        // create the non-modal dialog and kick off a 
        // thread to show it in 10 seconds time
        nonModalDialog = new Dialog(nonModalParentFrame, "Non modal", false);
        nonModalDialog.setBounds(400, 400, 100, 100);
        nonModalDialog.addMouseMotionListener(new DebugAdapter() );
        new Thread(this).start();

        // create the modal dialog and show it from this thread
        modalDialog = new Dialog(modalParentFrame, "Modal", true);
        modalDialog.setBounds(100, 400, 100, 100);
        modalDialog.addMouseMotionListener(new DebugAdapter() );
        modalDialog.setVisible(true);
    }

    public static void main(String [] args) {
        new DialogBug();
    }

    // This is the implementation of Runnable and is 
    // used to show the non-modal dialog in 10 seconds
    public void run() {
        try {
            Thread.currentThread().sleep(10 * 1000);
        } catch (InterruptedException e) {
            System.out.println("InterruptedException");
        }
        //show the non modal dialog
        nonModalDialog.setVisible(true);
    }
} 

class DebugAdapter extends MouseMotionAdapter {
    public void mouseMoved(MouseEvent e) {
        System.out.println(e);
    }
}
(Review ID: 88324) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-09-2004

WORK AROUND Name: skT88420 Date: 07/23/99 Don't show non-modal dialogs after modal dialogs and expect true modality ======================================================================
17-09-2004

EVALUATION Confirmed this bug is reproducible on JDK1.3 on WinNT, but not Solaris. mike.bronson@eng 1999-08-30 Still reproducable on Merlin 1.4 B89. Should fix for Hopper. ###@###.### 2001-12-10 Name: osR10079 Date: 12/17/2002 I'm unable to reproduce the problem with 1.4.0, 1.4.1 and 1.4.2 with all versions no mouse events were received by second (non-modal) dialog. ###@###.### 2002-12-17 ====================================================================== Well, it is true that modal dialog blocks mouse events, but it doesn't block key events, activation, focus. Tested with current 1.5 workspace. ###@###.### 2002-12-17
17-12-2002