JDK-4403757 : Modal Dialog does not block Drag&Drop events
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2001-01-11
  • Updated: 2002-10-08
  • Resolved: 2002-10-08
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: boT120536			Date: 01/10/2001


>> java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Run the following program.
Press the show button to display the modal dialog.
Move the modal dialog so it is not directly over the parent frame.
Press down on the label in the modal dialog and drag it over
the label on the parent frame.
Note that the label in the parent frame receives the dragOver
and drop events.

I would expect a modal dialog to block all events from reaching other
windows.

---------------------------------------------------------------------
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.awt.event.*;

public class DnDTest extends JPanel
{

    public static JFrame frame;

    public class DnDLabel extends JLabel implements DragSourceListener,
DropTargetListener, DragGestureListener
    {
        protected DragSource dragSource = DragSource.getDefaultDragSource();
        protected DropTarget dropTarget = null;
        public DnDLabel(String label)
        {
            super(label);
            dropTarget = new DropTarget (this, this);

            dragSource.createDefaultDragGestureRecognizer( this,
                  DnDConstants.ACTION_MOVE, this );
        }
        public void dragDropEnd(DragSourceDropEvent e) { }
        public void dragEnter(DragSourceDragEvent e) { }
        public void dragExit(DragSourceEvent e) { }
        public void dragOver(DragSourceDragEvent e) { }
        public void dropActionChanged(DragSourceDragEvent e) {}
        public void dragGestureRecognized(DragGestureEvent e)
        {
          System.out.println(getText() + " dragGestureRecognized");
          e.startDrag(null, new StringSelection("hello"), this);
        }

        public void dragEnter(DropTargetDragEvent dtde) { }
        public void dragExit(DropTargetEvent dte) { }
        public void dropActionChanged(DropTargetDragEvent dtde){}
        public void dragOver(DropTargetDragEvent dtde)
        {
          System.out.println(getText() + " dragOver");
        }
        public void drop(DropTargetDropEvent dtde)
        {
          System.out.println(getText() + " drop");
        }
    }

    public DnDTest()
    {
        super(new BorderLayout());
        JButton button = new JButton("Show");
        button.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JDialog dlg = new JDialog(frame, true);
                dlg.getContentPane().add("Center", new DnDLabel("Modal Label"));
                dlg.pack();
                dlg.setVisible(true);
            }
        });
        add("Center", new DnDLabel("Main Panel"));
        add("South", button);
    }

    public static void main(String[] args)
    {
        frame = new JFrame("DnD Test");
        frame.getContentPane().add("Center", new DnDTest());
        frame.pack();
        frame.setVisible(true);
    }
}
(Review ID: 111682) 
======================================================================

Comments
EVALUATION Name: agR10216 Date: 10/02/2002 This bug is not reproducible starting with JDK 1.4.1. The problem is the same as in the bug 4088877, which was fixed in 1.4. As a regression caused by the latter fix there was another bug 4633417 in 1.4, that causes the test app to lock. The bug 4633417 was fixed in 1.4.1, and the bug 4403757 is not reproducible any more. ###@###.### 2002-10-02 ====================================================================== Name: agR10216 Date: 10/02/2002 If the test case is modified so that a modal dialog is shown on a thread different from the event dispatch thread, then this bug reproduces. The modification is in the actionPerformed() method like this: public void actionPerformed(ActionEvent e) { final JDialog dlg = new JDialog(frame, true); dlg.getContentPane().add("Center", new DnDLabel("Modal Label")); dlg.pack(); new Thread(new Runnable() { public void run() { dlg.setVisible(true); } }).start(); } With the fixes for 4088877 and 4633417 while a modal dialog is shown any mouse and action events that is outside of the dialog hierarchy are filtered out and consume()d. But this occurs provided a modal dialog is shown on the event dispatch thread. The fix for 4645035 will resolve this problem so that those events will be filtered out as well as in case of a modal dialog is shown on a non-event dispatch thread. ###@###.### 2002-10-02 ====================================================================== Name: agR10216 Date: 10/08/2002 4636311 and its duplicate 4645035 have been fixed, so the bug 4403757 is not reproducible any more. ###@###.### 2002-10-08 ======================================================================
08-10-2002