views:

2337

answers:

6

I'm putting together a quick and dirty animation using swing (hehehe). I would like the window to be maximized. How can I do that?

Thanks in advance :)

+3  A: 

If your using a JFrame, try this

JFrame frame = new JFrame();
//...
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
+3  A: 

How about JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH)?

Zach Scrivena
+2  A: 

Something like this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);

import java.awt.*;
import javax.swing.*;

public class Test extends JFrame
{
    public Test()
    {
        GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
        this.setMaximizedBounds(env.getMaximumWindowBounds());
        this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
    }

    public static void main(String[] args)
    {
        JFrame.setDefaultLookAndFeelDecorated(true);

        Test t = new Test();
        t.setVisible(true);
    }
}
VonC
+2  A: 

This page may provide some help

JFrame maximisation

Greg Reynolds
+6  A: 

Provided that you are extending JFrame:

public void run() {
    MyFrame myFrame = new MyFrame();
    myFrame.setVisible(true);
    myFrame.setExtendedState(myFrame.getExtendedState() | myFrame.MAXIMIZED_BOTH);
}
kgiannakakis
A: 

hi,

i like this version:

[code] import java.awt.Dimension; import java.awt.GraphicsConfiguration; import java.awt.Toolkit; import javax.swing.JFrame;

public class Test { public static void main(String [] args) { final JFrame frame = new JFrame(); final GraphicsConfiguration config = frame.getGraphicsConfiguration();

    final int left = Toolkit.getDefaultToolkit().getScreenInsets(config).left;
    final int right = Toolkit.getDefaultToolkit().getScreenInsets(config).right;
    final int top = Toolkit.getDefaultToolkit().getScreenInsets(config).top;
    final int bottom = Toolkit.getDefaultToolkit().getScreenInsets(config).bottom;

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final int width = screenSize.width - left - right;
    final int height = screenSize.height - top - bottom;

    frame.setResizable(false);
    frame.setSize(width,height);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
    frame.setVisible(true);
}

} [/code]

frame_max_show