1import java.awt.Dimension;
2import javax.swing.JFrame;
3import javax.swing.SwingUtilities;
4
5public class JFrameSize
6{
7
8 public static void main(String[] args)
9 {
10 // schedule this for the event dispatch thread (edt)
11 SwingUtilities.invokeLater(new Runnable()
12 {
13 public void run()
14 {
15 displayJFrame();
16 }
17 });
18 }
19
20 static void displayJFrame()
21 {
22 // create our jframe as usual
23 JFrame jframe = new JFrame("JFrame Size Example");
24 jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25
26 // set the jframe size and location, and make it visible
27 jframe.setPreferredSize(new Dimension(400, 300));
28 jframe.pack();
29 jframe.setLocationRelativeTo(null);
30 jframe.setVisible(true);
31 }
32
33}
34