4747import sun .java2d .opengl .WGLGraphicsConfig ;
4848import sun .java2d .windows .WindowsFlags ;
4949
50+ import static java .awt .peer .ComponentPeer .SET_BOUNDS ;
51+
5052import static sun .awt .Win32GraphicsEnvironment .debugScaleX ;
5153import static sun .awt .Win32GraphicsEnvironment .debugScaleY ;
5254
@@ -443,6 +445,21 @@ public synchronized void setFullScreenWindow(Window w) {
443445 protected native void enterFullScreenExclusive (int screen , WindowPeer w );
444446 protected native void exitFullScreenExclusive (int screen , WindowPeer w );
445447
448+ /**
449+ * Reapplies the size of this graphics device to
450+ * the given full-screen window.
451+ * @param w a Window that needs resizing
452+ * @param b new full-screen window bounds
453+ */
454+ private static void resizeFSWindow (final Window w , final Rectangle b ) {
455+ if (w != null ) {
456+ WindowPeer peer = AWTAccessor .getComponentAccessor ().getPeer (w );
457+ if (peer != null ) {
458+ peer .setBounds (b .x , b .y , b .width , b .height , SET_BOUNDS );
459+ }
460+ }
461+ }
462+
446463 @ Override
447464 public boolean isDisplayChangeSupported () {
448465 return (isFullScreenSupported () && getFullScreenWindow () != null );
@@ -465,13 +482,9 @@ public synchronized void setDisplayMode(DisplayMode dm) {
465482 WWindowPeer peer = AWTAccessor .getComponentAccessor ().getPeer (w );
466483 configDisplayMode (screen , peer , dm .getWidth (), dm .getHeight (),
467484 dm .getBitDepth (), dm .getRefreshRate ());
468- // resize the fullscreen window to the dimensions of the new
469- // display mode
470- Rectangle screenBounds = getDefaultConfiguration ().getBounds ();
471- w .setBounds (screenBounds .x , screenBounds .y ,
472- screenBounds .width , screenBounds .height );
473- // Note: no call to replaceSurfaceData is required here since
474- // replacement will be caused by an upcoming display change event
485+ // Note: the full-screen window will get resized to the dimensions of the new
486+ // display mode in the upcoming display change event, when the DPI scales
487+ // would already be correctly set etc.
475488 } else {
476489 throw new IllegalStateException ("Must be in fullscreen mode " +
477490 "in order to set display mode" );
@@ -531,6 +544,10 @@ public void displayChanged() {
531544 defaultConfig = null ;
532545 configs = null ;
533546 initScaleFactors ();
547+
548+ Rectangle screenBounds = getDefaultConfiguration ().getBounds ();
549+ resizeFSWindow (getFullScreenWindow (), screenBounds );
550+
534551 // pass on to all top-level windows on this display
535552 topLevels .notifyListeners ();
536553 }
0 commit comments