How to maximize (or minimize) a JFrame

As a quick note today, here’s some code that shows how to maximize a JFrame:

MyJFrame myFrame = new MyJFrame();

// do other stuff here ...

// this maximizes the jframe
myFrame.setState(Frame.NORMAL);

// do whatever else you want to do ...
myFrame.setVisible();

How to minimize a JFrame

To minimize a JFrame just do this:

MyJFrame myFrame = new MyJFrame();

// do other stuff here ...

// minimize
myFrame.setState(Frame.ICONIFIED);

If you needed to see how to programmatically maximize and minimize a JFrame in Java, I hope that was helpful.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.