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

Window.setMinimumSize does not respect DPI scaling

XMLWordPrintable

    • 9
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Home, version 1809, build 17763.379
      openjdk version "12" 2019-03-19
      OpenJDK Runtime Environment (build 12+33)
      OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      The setMinimumSize implementation on java.awt.Window and derived classes always treats the specified size as unscaled physical screen pixels, regardless of current DPI scaling.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test program below. When the window appears, attempt to shrink it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Initial and minimum sizes are identical, therefore it should never be possible to shrink the window.
      ACTUAL -
      On any DPI setting greater than 100%, the window can be shrunk to the physical equivalent of the specified size. For example, at 200% scale the window size can be halved in both dimensions.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class MinSizeTest extends JFrame {
          private static final long serialVersionUID = 0;

          public static void main(final String[] args) {
              EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      final JFrame frame = new MinSizeTest();
                      frame.setVisible(true);
                  }
              });
          }

          MinSizeTest() {
              setTitle("Minimum Size Test");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              final Dimension size = new Dimension(400, 400);
              setSize(size);
              setMinimumSize(size);
              setResizable(true);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      One can listen to the componentResized event and restore a desired minimum size once the window has been resized below that. Unfortunately this produces some annoying flickering. The workaround is described here:
      https://news.kynosarges.org/2019/03/14/minimum-size-scaling-for-swing-windows/

      FREQUENCY : always


            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: