Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame scaling in Java 9

Tags:

java

java-9

swing

Exactly the same code running under Java 9u4 on the left and 8u144 on the right on Windows 7.

different window sizes

Java 9 seems to making the window larger. What is causing this - JEP 263? How can I disable it?

public class SimpleFrame {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new JLabel("Horse"));
        frame.setSize(new Dimension(200, 100));
        frame.setVisible(true);
    }
}
like image 738
Adam Avatar asked Feb 05 '18 12:02

Adam


People also ask

How do I make my JFrame maximized by default?

By default, we can minimize a JFrame by clicking on minimize button and maximize a JFrame by clicking on maximize button at the top-right position of the screen. We can also do programmatically by using setState(JFrame. ICONIFIED) to minimize a JFrame and setState(JFrame. MAXIMIZED_BOTH) to maximize a JFrame.

How do I set the width and height of a JFrame?

getScreenSize(); // get 2/3 of the height, and 2/3 of the width int height = screenSize. height * 2 / 3; int width = screenSize. width * 2 / 3; // set the jframe height and width jframe. setPreferredSize(new Dimension(width, height));


1 Answers

I found this obscure option in a substance bug report. This fixes the issue for Swing applications.

-Dsun.java2d.uiScale=1.0

If you're using JavaFX you'll need

-Dprism.allowhidpi=false

Unfortunately I cannot find official documentation for either of these options

like image 77
Adam Avatar answered Sep 30 '22 00:09

Adam