How to run JFrame maximized in JAVA?

Dishon Michael picture Dishon Michael · Apr 1, 2013 · Viewed 25.7k times · Source

I'm new to JAVA.

I need to run a JFrame named MainFrame in maximized mode.

How can I do it?

public class MainFrame extends javax.swing.JFrame {

/**
 * Creates new form MainFrame
 */
public MainFrame() {
    initComponents();
}

Answer

Vishal K picture Vishal K · Apr 1, 2013

You should use JFrame.setExtendedState:

public MainFrame() {
    initComponents();
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}