15

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();
}
mre
  • 43,520
  • 33
  • 120
  • 170
Dishon Michael
  • 157
  • 1
  • 2
  • 6

1 Answers1

42

You should use JFrame.setExtendedState:

public MainFrame() {
    initComponents();
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Vishal K
  • 12,976
  • 2
  • 27
  • 38
  • 1
    The last time I used Red Hat Enterprise Linux, the frame must be visible in order to set the extended state. It worked fine on windows despite the order. I'm not sure if this is still an issue. – Joseph Gordon Apr 01 '13 at 19:45
  • Just tested this on Windows 8.1: The frame had to be visible in order for it to work. – Håvard Geithus Mar 19 '14 at 22:10