How to maximize a JFrame through code?

How to maximize a JFrame through code?


Try this:

f.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH );

this works perfectly till java 7

public class TEST
{
    public static void main(String args[])
    {
        JFrame jf= new JFrame();
        jf.setVisible(true);
        jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
}

Yea the Toolkit solution ignores the windows task bar and uses the full screen which is not what you want.

For an immediate maximise of your form just add this in the JFrame constructor after the InitiateComponents() call.

this.setExtendedState(JFrame.MAXIMIZED_BOTH);

The class extends JFrame of course:

public class MyForm extends javax.swing.JFrame