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();
}
0

1 Answer 1

43

You should use JFrame.setExtendedState:

public MainFrame() {
    initComponents();
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}
2
  • 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. Apr 1, 2013 at 19:45
  • Just tested this on Windows 8.1: The frame had to be visible in order for it to work. Mar 19, 2014 at 22:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.