< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java

Print this page

        

@@ -79,10 +79,13 @@
      * Called (on the Toolkit thread) before the appropriate
      * WindowStateEvent is posted to the EventQueue.
      */
     private WindowListener windowListener;
 
+    private float scaleX;
+    private float scaleY;
+
     /**
      * Initialize JNI field IDs
      */
     private static native void initIDs();
     static {

@@ -188,11 +191,14 @@
             ((Window) target).setBackground(SystemColor.window);
         }
 
         // Express our interest in display changes
         GraphicsConfiguration gc = getGraphicsConfiguration();
-        ((Win32GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
+        Win32GraphicsDevice gd = (Win32GraphicsDevice) gc.getDevice();
+        gd.addDisplayChangedListener(this);
+        scaleX = gd.getDefaultScaleX();
+        scaleY = gd.getDefaultScaleY();
 
         initActiveWindowsTracking((Window)target);
 
         updateIconImages();
 

@@ -537,12 +543,27 @@
             newDev.addDisplayChangedListener(this);
         }
 
         AWTAccessor.getComponentAccessor().
             setGraphicsConfiguration((Component)target, winGraphicsConfig);
+
+        float newScaleX = newDev.getDefaultScaleX();
+        float newScaleY = newDev.getDefaultScaleY();
+
+        if (scaleX != newScaleX || scaleY != newScaleY) {
+            Window win = (Window) target;
+            setBounds(rescale(win.getX(), scaleX, newScaleX),
+                      rescale(win.getY(), scaleY, newScaleY),
+                      win.getWidth(), win.getHeight(), SET_BOUNDS);
+            scaleX = newScaleX;
+            scaleY = newScaleY;
+        }
     }
 
+    private static int rescale(int position, float oldScale, float newScale) {
+        return Math.round(position * oldScale / newScale);
+    }
     /**
      * From the DisplayChangedListener interface.
      *
      * This method handles a display change - either when the display settings
      * are changed, or when the window has been dragged onto a different
< prev index next >