I help maintain a large, very old Swing project. We noticed that the swing project pages running under JRE 11 look quite a bit different from the swing project running under JRE 8, our previous version.

I have been exploring this issue. One thing I noticed is that basic sizing seems to be different. JRE11 makes all the JFrames larger. We need to have the sizing stay consistent.

Here is a small program to demonstrate what I am seeing:

    import javax.swing.*;

public class JustAFrame
{
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(
                () -> {
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
                    frame.pack();
                    frame.setSize(400, 500);
                    frame.setVisible(true);
                });
    }
}

I ran this program on the same Windows 10 machine using java 64 bit version jdk1.8.0_241 and zulu11.41.23-ca-fx-jdk11.0.8-win_x64. I'm attaching an image showing the same class running in the two java versions side by side. The JRE 11 version appears to be about 50% larger. What can I do to make the JRE 11 JVM make our JFrames the size as our previous version of java, without having to go into every JFrame instance in our application and fiddling with the size Dimension parameter?

enter image description here

1

There are 1 answers

0
Akila On

This is due to after Java 9, windows scaling compatibility working correctly.
that means if your monitor is set to scale at 150%, the Java application is scaled to 150%. to disable this, use the following methods (worked for me in zulu11)

set VM option : -Dsun.java2d.uiScale=1.0

OR

System.setProperty("sun.java2d.uiScale", "1.0");

1.0 = 100%