< prev index next >

test/jdk/java/awt/dnd/Button2DragTest/Button2DragTest.java

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX

@@ -21,14 +21,14 @@
  * questions.
  */
 
 import java.awt.Color;
 import java.awt.Frame;
-import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
 import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.Robot;
 import java.awt.datatransfer.StringSelection;
 import java.awt.dnd.DnDConstants;
 import java.awt.dnd.DragGestureEvent;
 import java.awt.dnd.DragGestureListener;

@@ -45,20 +45,21 @@
 import test.java.awt.regtesthelpers.Util;
 
 /**
  * @test
  * @key headful
- * @bug 4955110 8238575
+ * @bug 4955110 8238575 8211999
  * @summary tests that DragSourceDragEvent.getDropAction() accords to its new
  *          spec (does not depend on the user drop action)
  * @library ../../regtesthelpers
  * @build Util
  * @run main/othervm Button2DragTest
  * @author Alexander.Gerasimov area=dnd
  */
 public final class Button2DragTest {
 
+    private static final int SIZE = 200;
     private volatile boolean dropSuccess;
     private volatile boolean locationValid = true;
 
     private static Frame frame;
 

@@ -77,12 +78,12 @@
 
     public void run() {
         final DragSourceListener dragSourceListener = new DragSourceListener() {
             private void checkLocation(DragSourceEvent dsde) {
                 if (!frame.getBounds().contains(dsde.getLocation())) {
-                    System.err.println("Expected in" + frame.getBounds());
-                    System.err.println("Actual" + dsde.getLocation());
+                    System.err.println("Expected in: " + frame.getBounds());
+                    System.err.println("Actual: " + dsde.getLocation());
                     locationValid = false;
                 }
             }
 
             @Override

@@ -128,12 +129,14 @@
         };
         new DropTarget(frame, dropTargetListener);
 
         frame.setBackground(Color.GREEN);
         frame.setUndecorated(true);
-        frame.setSize(200, 200);
-        frame.setLocationRelativeTo(null);
+        Rectangle screen = frame.getGraphicsConfiguration().getBounds();
+        int x = (int) (screen.getCenterX() - SIZE / 2);
+        int y = (int) (screen.getCenterY() - SIZE / 2);
+        frame.setBounds(x, y, SIZE, SIZE);
         frame.setVisible(true);
 
         Robot robot = Util.createRobot();
 
         Util.waitForIdle(robot);
< prev index next >