JDK-8221452 : Window.setMinimumSize does not respect DPI scaling
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 9,11,12,13
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-03-25
  • Updated: 2019-04-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
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



Comments
Additional comment from submitter: "For the record, JavaFX had the same bug concerning the minimum and maximum sizes of its Stage class (equivalent to AWT Window). In that case too the current Stage size scaled correctly, only the min/max sizes didn't. That bug got fixed in JavaFX 9, shipping with Java SE 9 back then. Perhaps it would be instructive to take a look at the fix".
05-04-2019

I haven't confirmed this yet but it is interesting if is specific to setting the minimum size, and setSize() does things differently.
26-03-2019

Reported with JDK 12, 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. Checked this with reported version and could confirm the issue as a regression in JDK 9. Results: ========= 8u201: OK 9: Fail 11.0.2: Fail 12: Fail 13 ea b13 To verify, run the attached test case with respective JDK version. The windows does get shrink-ed even though the initial and minimum sizes are identical.
26-03-2019