问题
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