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

Setting cursor on DragSourceContext does not work on OSX

    XMLWordPrintable

Details

    • b86
    • x86
    • os_x

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.7.0_07"
        Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
        Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Mac OS X 10.7.4
        Darwin Kernel Version 11.4.0: RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        When setting the cursor on a DragSourceContext object during a drag operation, the cursor does not change it appearance. According to the documentation of DragSourceContext this should work. Under Windows it does show the appropriate behavior, but under Mac OS X the cursor does not change it appearance.

        Tested with different JREs: Java 6 and 7 and OpenJDK 8 all show incorrect behavior on OS X.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Implement a DragSourceListener and DragGestureListener and attach it to a Component. Set the cursor using the setCursor method in DragSourceContext. The DragSourceContext can be obtained using the DragSourceDragEvent parameters in the dragEnter and dragOver methods.

        Alternatively, a DragSourceMotionListener can be added to the DragSource on a Component. The cursor can then be set, using the same setCursor method in DragSourceContext, in the dragMouseMoved method.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The cursor should change it appearance to the custom component when dragging an object.
        ACTUAL -
        The cursor does not change it appearance at all.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.Cursor;
        import java.awt.Dimension;
        import java.awt.datatransfer.StringSelection;
        import java.awt.dnd.DnDConstants;
        import java.awt.dnd.DragGestureEvent;
        import java.awt.dnd.DragGestureListener;
        import java.awt.dnd.DragSource;
        import java.awt.dnd.DragSourceDragEvent;
        import java.awt.dnd.DragSourceDropEvent;
        import java.awt.dnd.DragSourceEvent;
        import java.awt.dnd.DragSourceListener;
        import java.awt.dnd.DragSourceMotionListener;

        import javax.swing.JFrame;
        import javax.swing.JList;
        import javax.swing.JPanel;
        import javax.swing.JTextArea;
        import javax.swing.ListSelectionModel;

        public class CustomCursorDSCTest extends JFrame implements DragSourceListener, DragGestureListener
        {
          private JList<String> list;
          
          public CustomCursorDSCTest()
          {
            super("DragSourceContext setCursor Test");
            setSize(300, 350);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.getContentPane().add(new ComponentPanel());
            DragSource ds = new DragSource();
            ds.createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, this);
            ds.addDragSourceMotionListener(new MotionListener());
            setVisible(true);
          }

          public void dragGestureRecognized(DragGestureEvent dge)
          {
            StringSelection transferable = new StringSelection(list.getSelectedValue().toString());
            dge.getDragSource().startDrag(dge, DragSource.DefaultCopyDrop, transferable, this);
          }

          public void dragEnter(DragSourceDragEvent dsde)
          {
            System.out.println("Drag enter, setting cursor");
            dsde.getDragSourceContext().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
          }

          public void dragOver(DragSourceDragEvent dsde)
          {
            System.out.println("Drag over, setting cursor");
            dsde.getDragSourceContext().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
          }

          public void dropActionChanged(DragSourceDragEvent dsde)
          {
          }

          public void dragExit(DragSourceEvent dse)
          {
            System.out.println("Drag exit");
          }

          public void dragDropEnd(DragSourceDropEvent dsde)
          {
            System.out.println("Drag end");
          }
          
          private class ComponentPanel extends JPanel
          {
            public ComponentPanel()
            {
              String[] items = {"Java", "C", "C++", "Lisp", "Perl", "Python"};
              list = new JList<String>(items);
              list.setPreferredSize(new Dimension(75, 150));
              list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              JTextArea textArea = new JTextArea(6, 20);
              this.add(list);
              this.add(textArea);
            }
          }
          
          private class MotionListener implements DragSourceMotionListener
          {
            public void dragMouseMoved(DragSourceDragEvent dsde)
            {
              dsde.getDragSourceContext().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            }
          }
          
          public static void main(String args[])
          {
            new CustomCursorDSCTest();
          }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Setting the cursor on a component does seem to work. A workaround would be to install a glasspane when dragging and setting the cursor on this glasspane.

        Attachments

          Issue Links

            Activity

              People

                pchelko Petr Pchelko (Inactive)
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: