Why does getPreferredSize() return (0,0) for my frame? (Or why does pack() crunch my frame to nothing?)

Scott Stanchfield

This happens if you don't have a layout manager set for the components inside the frame.

If you use appropriate layout managers, you should see decent results from pack().

For details on using layout managers, see http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/index.html