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

Cursor not modified during Drag and Drop



    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.4.2
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:
    • Verification:


      Name: boT120536 Date: 01/23/2001

      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)

      When initiating a DnD operation within a JTree, the JTree acts as both a
      source and a target. When the JTree rejects the drag, the cursor should change
      to the NoDrop cursor, but does not. If you hit the Shift key, the
      DropTargetListener receives the "dropActionChanged" message and the cursor is
      properly changed to the NoDrop cursor.

      Also, when the drag is rejected by the DropTargetListener, the
      DropSourceListener does NOT receive the "dragExit" message as stated in section
      2.3.3 of the "Drag and Drop Subsystem for JFC" document

      By the way, I tried this using JDK 1.2.2 on NT4 and encountered the same
      // ~~~~~~~~~~~~~~~~~ code sample follows ~~~~~~~~~~~~~~~~~~~~

      The following test program demonstrates several cursor problems in the DnD

      Try dragging a "true" node within the tree. The drag is rejected by the
      DropTargetListener, but the cursor never changes to the NoDrop cursor!

      Also, the DragSourceListener only receives the "dragEnd" and "dragDropEnd"
      messages, never the "dragEnter" or "dragOver" messages.

      Lastly, the cursor never changes when you drag over a component (JLabel
      or JButton) with no associated DropTarget. Shouldn't the cursor change
      to the NoDrop cursor?

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

      import javax.swing.*;
      import javax.swing.tree.*;

      public class DndTree extends JPanel
         /** scrollpane to display tree */
         protected JScrollPane scrollPane = new JScrollPane();

         /** JTree displaying the server */
         protected JTree serverTree = new JTree();

         /** root node of the tree */
         protected DefaultMutableTreeNode root;

         /** tree model */
         protected DefaultTreeModel model;

         // DND related vars
         protected DragSource myDragSource;
         protected DndSourceHandler dndSource;
         protected DndTargetHandler dndTarget;
         protected DropTarget myDropTarget;

          * Constructor.
         public DndTree()
            catch(Exception ex)

            root = new DefaultMutableTreeNode("root");

            // give the tree a model using root
            model = new DefaultTreeModel(root);

            // add some child nodes
            model.insertNodeInto(new DefaultMutableTreeNode(new Boolean(true)), root,
            model.insertNodeInto(new DefaultMutableTreeNode(new Boolean(false)), root,
            model.insertNodeInto(new DefaultMutableTreeNode(new Boolean(false)), root,
            model.insertNodeInto(new DefaultMutableTreeNode(new Boolean(true)), root,

            // set other tree display properties
            serverTree.putClientProperty("JTree.lineStyle", "Angled");

            // setup DND for dragging IElements into the Task Editor
            myDragSource = new DragSource();
            dndSource = new DndSourceHandler();
                                               DnDConstants.ACTION_MOVE, dndSource);

            // setup DND target to receive drags within tree
            dndTarget = new DndTargetHandler();
            myDropTarget = new DropTarget(serverTree, dndTarget);


         private void jbInit() throws Exception
            this.setLayout(new BorderLayout());
            this.add(new JLabel("just some text", JLabel.CENTER), BorderLayout.NORTH);
            this.add(scrollPane, BorderLayout.CENTER);
            this.add(new JButton("RIGHT"), BorderLayout.EAST);
            this.add(new JButton("LEFT"), BorderLayout.WEST);
            scrollPane.getViewport().add(serverTree, null);


          * Allows the JTree to act as a drag source
         private class DndSourceHandler implements DragSourceListener,
            public void dragGestureRecognized(DragGestureEvent dge)
               TreePath path = serverTree.getSelectionPath();
               if (null == path)

               DefaultMutableTreeNode node = (DefaultMutableTreeNode)
               Boolean b = (Boolean) node.getUserObject();
               if ( b.booleanValue() == true ) {

                  // create an object to contain our data
                  Transferable t = (Transferable) new StringSelection(b.toString());

                  // start the DnD drag operation
                  myDragSource.startDrag(dge, DragSource.DefaultLinkDrop, t,
                  System.out.println("source starting drag!");
            public void dragEnter(DragSourceDragEvent dsde) {
               System.out.println("source dragEnter: " + dsde.getTargetActions());
            public void dragExit(DragSourceEvent dse) {
               System.out.println("source dragExit: " +
            public void dragDropEnd(DragSourceDropEvent dsde) {
               System.out.println("source dragDropEnd: " + dsde.getDropAction());
            public void dragOver(DragSourceDragEvent dsde) {
               System.out.println("source dragOver: " + dsde.getTargetActions());
            public void dropActionChanged(DragSourceDragEvent dsde) {
               System.out.println("source dropActionChanged: " +


          * Allows JTree to act as a drop target
         protected class DndTargetHandler implements DropTargetListener {
            public void dragEnter(DropTargetDragEvent dtde) {
               System.out.println("target rejecting drag!");
               System.out.println("target dragEnter: " + dtde.getDropAction());
            public void dragOver(DropTargetDragEvent dtde) {
            public void drop(DropTargetDropEvent dtde) {
               // reject the drop
               System.out.println("target rejecting drop!");
               System.out.println("target dragEnter: " + dtde.getDropAction());
            public void dragExit(DropTargetEvent dte) {
               System.out.println("target dragExit: " +
            public void dropActionChanged(DropTargetDragEvent dtde) {
               System.out.println("target dropActionChanged: " +

         // TESTING ONLY !!
         static public void main(String[] argv) {
            // create a frame
            final JFrame frame = new JFrame("DndTree Frame");
            frame.setSize(300, 200);
            frame.setLocation(350, 250);
            // create a dialog based on the frame
            JDialog dialog = new JDialog(frame, "DnD Tree Tester", true);
            dialog.getContentPane().setLayout(new BorderLayout());
            dialog.setSize(new Dimension(400, 350));
            dialog.setLocation(300, 200);
            // add the tree panel to the dialog
            DndTree panel = new DndTree();
            dialog.getContentPane().add(panel, BorderLayout.CENTER);

      (Review ID: 112887)


          Issue Links



              agerasimsunw Alexander Gerasimov (Inactive)
              bonealsunw Bret O'neal (Inactive)
              0 Vote for this issue
              0 Start watching this issue