Java how to make JFrames start off as a maximised window

纵饮孤独 提交于 2019-12-10 15:00:33

问题


I want to know how to make a java JFrame start out maximised. I don't want it to be fullscreen (no window around it) I just want it to start out like a normal program such as a web browser.

I already know about using:

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

To get the screen size, but when you apply this Dimension to the JFrame it can still be dragged around even though it takes up almost all of the screen. You can press the maximse button to stop this but I would rather that the window started out maximised.

Also, I fear for the effects that maximising the window would have upon the contents of the window.

How do I go about doing this?


回答1:


Use java.awt.Frame.setExtendedState():

public static void main(String[] args)  {

    JFrame frame = new JFrame();
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setVisible(true);
}


来源:https://stackoverflow.com/questions/14881117/java-how-to-make-jframes-start-off-as-a-maximised-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!