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

Drag n Drop target area is wrong on high DPI systems

XMLWordPrintable

    • b12
    • x86_64
    • linux

        A DESCRIPTION OF THE PROBLEM :
        The area of a drop target that actually responds to events is calculated incorrectly on high DPI linux systems. The position of the frame relative to the overall space available on the monitor also seems to have something to do with it.

        The attached example should print to the console when something is dragged over the panel bordered in red. It does not respond correctly on high DPI systems unless disable high DPI scaling completely with -Dsun.java2d.uiScale.enabled=false

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Drag any file into the red outline.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Drop events are printed to the console anywhere in the red outline.
        ACTUAL -
        Only some areas of the frame result in drop events being printed, depending where the frame is located on your monitor.

        ---------- BEGIN SOURCE ----------
        import java.awt.BorderLayout;
        import java.awt.Color;
        import java.awt.Dimension;
        import java.awt.dnd.DropTarget;
        import java.awt.dnd.DropTargetDragEvent;
        import java.awt.dnd.DropTargetDropEvent;
        import java.awt.dnd.DropTargetEvent;
        import java.awt.dnd.DropTargetListener;
        import javax.swing.BorderFactory;
        import javax.swing.Box;
        import javax.swing.JFrame;
        import javax.swing.JPanel;

        class Scratch {
            public static void main(String[] args) {
                JFrame frame = new JFrame("Drag n Drop Test");
                frame.setSize(640, 480);
                frame.setLayout(new BorderLayout());

                JPanel panel = new JPanel();
                panel.setBorder(BorderFactory.createLineBorder(Color.RED));
                panel.setSize(320, 240);
                panel.setPreferredSize(new Dimension(320, 240));
                panel.setMaximumSize(new Dimension(320, 240));

                new DropTarget(panel, new DropTargetListener() {
                    @Override
                    public void dragEnter(DropTargetDragEvent dtde) {
                        System.out.println("dragEnter");
                    }

                    @Override
                    public void dragOver(DropTargetDragEvent dtde) {
                        System.out.println("dragOver");
                    }

                    @Override
                    public void dropActionChanged(DropTargetDragEvent dtde) {
                        System.out.println("dropActionChanged");
                    }

                    @Override
                    public void dragExit(DropTargetEvent dte) {
                        System.out.println("dragExit");
                    }

                    @Override
                    public void drop(DropTargetDropEvent dtde) {
                        System.out.println("drop");
                    }
                });

                frame.add(Box.createVerticalStrut(120), BorderLayout.NORTH);
                frame.add(Box.createVerticalStrut(120), BorderLayout.SOUTH);
                frame.add(Box.createHorizontalStrut(160), BorderLayout.WEST);
                frame.add(Box.createHorizontalStrut(160), BorderLayout.EAST);
                frame.add(panel, BorderLayout.CENTER);
                frame.setVisible(true);
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : always


          1. Capture.JPG
            Capture.JPG
            68 kB
          2. HiDPI.png
            HiDPI.png
            19 kB
          3. Scale.png
            Scale.png
            17 kB
          4. Scratch.java
            2 kB

              omikhaltcova Olga Mikhaltcova
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: