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 :)
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 :)
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);
}
}
Provided that you are extending JFrame:
public void run() {
MyFrame myFrame = new MyFrame();
myFrame.setVisible(true);
myFrame.setExtendedState(myFrame.getExtendedState() | myFrame.MAXIMIZED_BOTH);
}
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]