public static void main(String args[]){
JFrame frame = new JFrame();
frame.setExtendedState(JFrame.MAXIMISED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
I've used this code to maximise a JFrame, but instead of actually maximising the frame, it just sets the window size to that of the screen, without actually changing the state, so clicking the maximize button doesn't actually downscale it again.
Am I using the wrong command or something?
It works for me running Java 7 on a WinXP machine.
For the record, this is what an SSCCE should look like:
You must want it maximized by default. Because the maximize button works out-of-the-box.
frame.setExtendedState(JFrame.MAXIMIZED_BOTH)
works on Linux x64. Here's the program I tested with:Based on your provided example and run on Windows 7...
"Maximised" state (this is cropped version of window as the original is quite large)
"Normal" state
This worked for me:
We need to combine the setSize () and setExtendedState together JFrame frame=new JFrame();
You should use this when applying changes
You have an error in
frame.setExtendedState(JFrame.MAXIMISED_BOTH);
You should write
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
instead