< prev index next >

test/jdk/javax/swing/JTextArea/8149849/DNDTextToScaledArea.java

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

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -22,41 +22,53 @@
  */
 
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
 import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.Robot;
 import java.awt.event.InputEvent;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.JTextArea;
 import javax.swing.SwingUtilities;
 
 /**
  * @test
  * @key headful
- * @bug 8149849
+ * @bug 8149849 8211999
  * @summary [hidpi] DnD issues (cannot DnD from JFileChooser to JEditorPane or
  *          other text component) when scale > 1
+ * @run main/othervm DNDTextToScaledArea
  * @run main/othervm -Dsun.java2d.uiScale=2 DNDTextToScaledArea
  */
 public class DNDTextToScaledArea {
 
+    private static final int SIZE = 300;
     private static final String TEXT = "ABCDEFGH";
     private static JFrame frame;
     private static JTextArea srcTextArea;
     private static JTextArea dstTextArea;
     private static volatile Point srcPoint;
     private static volatile Point dstPoint;
     private static volatile boolean passed = false;
 
     public static void main(String[] args) throws Exception {
+        var lge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        for (GraphicsDevice device : lge.getScreenDevices()) {
+            test(device);
+        }
+    }
+
+    private static void test(GraphicsDevice device) throws Exception {
         Robot robot = new Robot();
         robot.setAutoDelay(50);
 
-        SwingUtilities.invokeAndWait(DNDTextToScaledArea::createAndShowGUI);
+        SwingUtilities.invokeAndWait(() -> createAndShowGUI(device));
         robot.waitForIdle();
 
         SwingUtilities.invokeAndWait(() -> {
             srcPoint = getPoint(srcTextArea, 0.1);
             dstPoint = getPoint(dstTextArea, 0.75);

@@ -75,15 +87,16 @@
         if (!passed) {
             throw new RuntimeException("Text Drag and Drop failed!");
         }
     }
 
-    private static void createAndShowGUI() {
-
-        frame = new JFrame();
-        frame.setSize(300, 300);
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    private static void createAndShowGUI(GraphicsDevice device) {
+        frame = new JFrame(device.getDefaultConfiguration());
+        Rectangle screen = device.getDefaultConfiguration().getBounds();
+        int x = (int) (screen.getCenterX() - SIZE / 2);
+        int y = (int) (screen.getCenterY() - SIZE / 2);
+        frame.setBounds(x, y, SIZE, SIZE);
 
         JPanel panel = new JPanel(new BorderLayout());
 
         srcTextArea = new JTextArea(TEXT);
         srcTextArea.setDragEnabled(true);
< prev index next >