JDK-4793073 : REGRESSION: Non-modal JDialog gets keyevents when launched from modal dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1,1.4.2,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2002-12-12
  • Updated: 2005-06-05
  • Resolved: 2005-06-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b40Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Name: jk109818			Date: 12/12/2002


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

FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When non-modal dialog is launched from modal dialog it
receives keyboard events but not mouse events. It should
not receive any events.

REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile code provided, and start program.
2. In the frame click "Open modal dialog" button. The modal
dialog will popup.
3. Press "Open non-modal dialog" button. Another dialog will
popup.
4. Use "Tab" key to switch between controls of type in the
text field - key events happen.
5. Now try mouse clicks on any of the controls - nothing
happens.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Key events should not go through (as in version 1.3.1)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class SwingBug {
    public static void main(String[] args) throws Exception {
        final JFrame f = new JFrame("Frame");
        final JDialog d1 = new JDialog(f, "Modal Dialog", true);
        final JButton b2 = new JButton("Open non-modal dialog");
        b2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JDialog d2 = new JDialog(f, "Non-Modal Dialog", false);
                d1.setEnabled(false);
                d2.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e2) {
                        d1.setEnabled(true);
                    }
                });
                JPanel p = new JPanel();
                p.add(new JTextField(10));
                p.add(new JCheckBox("checkbox 1"));
                p.add(new JCheckBox("checkbox 2"));
                d2.getContentPane().add(p);
                d2.pack();
                d2.setVisible(true);
            }
        });
        JButton b1 = new JButton("Open modal dialog");
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                d1.getContentPane().add(b2);
                d1.pack();
                d1.setVisible(true);
            }
        });
        f.getContentPane().add(b1);
        f.pack();
        f.show();
    }
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_06
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: 165912) 
======================================================================

Comments
EVALUATION Name: osR10079 Date: 12/17/2002 I see two problems: 1. regression from 1.3.1_06: KeyEvents are delivered to non-modal dialog. 2. in all versions this dialog is not disabled as it should be because of modality of another dialog. The first problem is caused by new dispatching scheme for KeyEvent. Now we do not consume them in EventQueue if their source is not under current modal dialog, but retarget them to current focus owner. But because of the second problem some component in non-modal dialog recives focus and KeyEvents are dispatched to it. I think that correct approach for this bug is fixing second issue and then first one will disappear. ###@###.### 2002-12-17 ======================================================================
17-12-2002