/** * @author L a u tturi.com * Java Swing Example: java JFrame pack method */ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Lautturi { public static void main(String[] args) { JFrame frame = new JFrame("Java Swing - lautturi"); JPanel panel = new JPanel(); JButton button1 = new JButton("button1"); JButton button2 = new JButton("button2"); panel.add(button1); panel.add(button2); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 300); frame.setLocationRelativeTo(null); // sets size for the frame to fit the preferred size and layouts of its subcomponents frame.pack(); frame.setVisible(true); } }Source:al.wwwutturi.com