Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4337114

Drag and Drop does not work correctly when JInternalFrame selection changes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0, 1.3.0
    • client-libs
    • x86
    • solaris_2.6, windows_nt, windows_2000



      Name: skT45625 Date: 05/10/2000


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


      The following code illustrates two possible bugs with JDK's dnd. First occurs
      on both JDK 1.3RC1 and JDK 1.2.2, second only occurs on JDK 1.3RC1.
      Steps:
      1. Save code to file Test.java
      2. Compile with javac Test.java
      3. run java Test

      There are two internal frames. Frame 1 is selected. Click Frame 2 to get it
      selected.

      PROBLEM 1.
      Now click on the label in Frame 1. (Click and release the button). You may now
      move the mouse and see that drag and drop is in progres even though no buttons
      are pressed.
      This problem occurs in both JDK 1.3RC1 and JDK 1.2.2

      PROBLEM 2.

      When you initiated dnd in Frame 1, try to drop on Frame 2. In JDK 1.2.2 it will
      work correctly. Cursor will change as you enter and "Drop" will be printed as
      you drop. However, in JDK 1.3RC1 the drop will not be accepted.

      IMPORTANT.
      If you don't select Frame 2 at least once, you will not be able to reproduce
      any of the problems. So follow steps exactly.

      CODE:

      import java.awt.*;
      import javax.swing.*;
      import java.awt.datatransfer.*;
      import java.awt.dnd.*;

      public class Test extends JFrame
      {
        public static void main(String[] args)
        {
            (new Test()).showFrame();
        }

        public void showFrame()
        {
          setTitle("Drag and Drop test");
          Container cont = getContentPane();
          JDesktopPane desk = new JDesktopPane();
          cont.add( desk );

          JInternalFrame iframe1 = new JInternalFrame("Frame 1");
          JInternalFrame iframe2 = new JInternalFrame("Frame 2");

          JLabel label1 = new JLabel("Click here when frame is unselected");
          JLabel label2 = new JLabel("Try to drop here");
          JPanel panel1 = new JPanel(new BorderLayout());
          JPanel panel2 = new JPanel(new BorderLayout());
          panel1.add(label1);
          panel2.add(label2);
          dsListener = new DSListener();


            DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
                                             label1,
                                             DnDConstants.ACTION_COPY_OR_MOVE,
                                             new DGListener());

          iframe1.getContentPane().add(panel1);
          iframe2.getContentPane().add(panel2);
          iframe1.setBounds(20,20, 300,100);
          iframe2.setBounds(320, 20, 300,100);

          desk.add(iframe1);
          desk.add(iframe2);
          iframe1.setVisible(true);
          iframe2.setVisible(true);

          setSize(700,400);
          setVisible(true);
          try
          {
             iframe1.setSelected(true);
          }
          catch(Exception e)
          {}
          DropTarget target = new DropTarget(label2,DnDConstants.ACTION_COPY, new
      DTListener(), true);
        }

        class DGListener implements DragGestureListener
        {
          public void dragGestureRecognized(DragGestureEvent e)
          {

            Transferable transferable = new StringSelection("Test");
            e.startDrag(DragSource.DefaultCopyNoDrop,
                transferable,
                dsListener);

          }
        }

        class DSListener implements DragSourceListener
        {
          public void dragDropEnd(DragSourceDropEvent e) {}
          public void dragEnter(DragSourceDragEvent e) {}
          public void dragOver(DragSourceDragEvent e) {}
          public void dragExit(DragSourceEvent e) {}
          public void dropActionChanged (DragSourceDragEvent e) {}
        }

        class DTListener implements DropTargetListener
        {
            
            public DTListener()
            {
            }
            
            public void dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
            {
                    dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
            }
            
            public void dragExit(java.awt.dnd.DropTargetEvent dte)
            {
            }
            
            public void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
            {
                    dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
            }
            
            public void drop(java.awt.dnd.DropTargetDropEvent dtde)
            {
                 System.out.println("Drop");
            }
            
            public void dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
            {
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
            }
        };

        private DragSourceListener dsListener;
      }
      (Review ID: 102940)
      ======================================================================

            dassunw Das Das (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: