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

Cursor not modified during Drag and Drop



    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
    • OS:


      Java Version: 1.5.0-rc-b63
      Platform: Solaris10_b66-IAx86 with JDS release 3(cinnabar-b16)

      The problem:
      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.

      Please see bug4407521 which fixed in mantis.
      But the problem only happens in IA10_b66 with JDS, sparc10_b66(JDS) is ok. Other platfroms are OK too.

      To reproduce:
      using b63 java to compile and run DndTree.java

      The code is as followings:
      // ~~~~~~~~~~~~~~~~~ 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);



          Issue Links



              agerasimsunw Alexander Gerasimov (Inactive)
              ttzhang Tao Zhang
              0 Vote for this issue
              0 Start watching this issue