JFrame doesn't take the actual screen size

后端 未结 2 434
温柔的废话
温柔的废话 2021-01-27 20:42

I have been trying to set the size of my JFrame to the exact same size of my screen (2256x1504). It also seems to take that size but when I display something the outcome is alw

2条回答
  •  北海茫月
    2021-01-27 20:54

    I have been trying to set the size of my JFrame to the exact same size of my screen (2256x1504).

    Don't use magic numbers. Each computer can be using a screen with a different resolution. Let Swing determine the size. Use:

    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    

    So the basic structure of the code would be:

    JPanel panel = new JPanel();
    add( panel );
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setAlwaysOnTop(true);
    setUndecorated(true);
    //setResizable(false); // not needed since the title bar is removed
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    //pack(); // not needed since the frame will be the screen size
    setVisible(true);
    

提交回复
热议问题