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

DnD ACTION_COPY to JScrollPane shows "No Drop Target" cursor erroneously on NT

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_nt

      Description


      Customer downloaded a DnD example from Developer Connection.
      The example works fine, however the drop target does not display the correct
      "Drop Target" cursor, but the "No Drop Target" cursor ("Drop vorbidden")
      instead.

      The problem cannot be reproduced on Solaris w/ JDK 1.2, but on NT 4.0 w/
      jre12-win32.exe java full version "JDK-1.2-V"
      jdk1_2_1-win.exe java full version "JDK-1.2.1-A"
      jre1_2_2rc1-win.exe java full version "JDK-1.2.2-U"

      I had Service Pack 3 installed on NT.


      The problem can be reproduced as follows:

      1. Testcase:

       The testcase consists of the three following files:
      DragAndDropTest.java
      DraggableLabel.java
      DroppableList.java

      ------------------------------------
      % more DragAndDropTest.java


      import java.awt.BorderLayout;
      import java.awt.Frame;

      import java.awt.event.WindowEvent;
      import java.awt.event.WindowAdapter;

      import javax.swing.JScrollPane;


      public class DragAndDropTest {

          public static void main (String args[]) {
              Frame f = new Frame("Tester");
              DraggableLabel north = new DraggableLabel("One");
              DraggableLabel south = new DraggableLabel("Two");
              DraggableLabel east = new DraggableLabel("Three");
              DraggableLabel west = new DraggableLabel("Four");
              DroppableList list = new DroppableList();
              JScrollPane pane = new JScrollPane (list);
              f.add (north, BorderLayout.NORTH);
              f.add (south, BorderLayout.SOUTH);
              f.add (east, BorderLayout.EAST);
              f.add (west, BorderLayout.WEST);
              f.add (pane, BorderLayout.CENTER);
              f.setSize (300, 300);
              f.addWindowListener (new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
              f.setVisible (true);
          }

      }
      ------------------------------------

      % more DraggableLabel.java:


      import java.awt.dnd.DragGestureListener;
      import java.awt.dnd.DragSourceListener;
      import java.awt.dnd.DnDConstants;
      import java.awt.dnd.DragSource;
      import java.awt.dnd.DragGestureEvent;
      import java.awt.dnd.DragSourceEvent;
      import java.awt.dnd.DragSourceDragEvent;
      import java.awt.dnd.DragSourceDropEvent;

      import java.awt.datatransfer.StringSelection;

      import javax.swing.JLabel;


      public class DraggableLabel extends JLabel implements DragSourceListener,
                                                             DragGestureListener {

          // Attribute

          private DragSource dragSource;

          // Konstruktor

          public DraggableLabel(String s) {
              super (s);

              dragSource = new DragSource();
              dragSource.createDefaultDragGestureRecognizer(
                  this,DnDConstants.ACTION_COPY, this);
          }

          // Implementierung von DragSourceListener

          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) {
          }

          // Implementierung von DragGestureListener

          public void dragGestureRecognized(DragGestureEvent e) {
              StringSelection text = new StringSelection(getText());

              dragSource.startDrag(e,DragSource.DefaultCopyDrop,text,this);
          }

      }
      ------------------------------------

      % more DroppableList.java


      import java.awt.datatransfer.DataFlavor;
      import java.awt.datatransfer.Transferable;
      import java.awt.datatransfer.UnsupportedFlavorException;

      import java.awt.dnd.DropTargetListener;
      import java.awt.dnd.DnDConstants;
      import java.awt.dnd.DragSource;
      import java.awt.dnd.DropTarget;
      import java.awt.dnd.DropTargetDragEvent;
      import java.awt.dnd.DropTargetDropEvent;
      import java.awt.dnd.DropTargetEvent;

      import java.io.IOException;

      import java.util.Vector;

      import javax.swing.JList;


      public class DroppableList extends JList implements DropTargetListener {

          private DropTarget dropTarget;

          private Vector v = new Vector();
                       
          public DroppableList() {
              dropTarget = new DropTarget(this,this);
          }

          public void dragEnter (DropTargetDragEvent e) {
              e.acceptDrag (DnDConstants.ACTION_COPY);
          }

          public void dragExit (DropTargetEvent e) {
          }

          public void dragOver (DropTargetDragEvent e) {
          }

          public void drop (DropTargetDropEvent e) {
              try {
                  Transferable tr = e.getTransferable();
                  if (tr.isDataFlavorSupported (DataFlavor.stringFlavor)) {
                      e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                      String s = (String)tr.getTransferData(
                          DataFlavor.stringFlavor);
                      v.add(s);
                      setListData(v);
                      paintImmediately(getVisibleRect());
                      e.getDropTargetContext().dropComplete(true);
                  } else {
                      System.err.println ("Rejected");
                      e.rejectDrop();
                  }
              } catch (IOException io) {
                  io.printStackTrace();
                  e.rejectDrop();
              } catch (UnsupportedFlavorException ufe){
                  ufe.printStackTrace();
                  e.rejectDrop();
              }
          }

          public void dropActionChanged(DropTargetDragEvent e) {
          }
      }
      ------------------------------------


      2. Compile and run the example:

       % java DragAndDropTest

       - The applications pops up.
       - Click to one of the labels called "One", "Two", "Three", "Four".
       - Drag the label and you will see the "Drop Target" cursor.
       _ As soon as you enter the JScrollPane component, the cursor changes to
         a "No Drop Target" cursor.
       - On release of the mouse button, the label is copied as supposed.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                xdengsunw Xianfa Deng (Inactive)
                Reporter:
                thlenz Thomas Lenz (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: