JDialog和JFrame一样,里面所有的面积不完全能用来放东西,只能调用getContentPane来获得能放东西的地方。
JPanel则完全可以放东西,所以可以直接掉add方法。The JFrame class is slightly incompatible with java.awt.Frame. JFrame contains a JRootPane as it's only child. The contentPane should be the parent of any children of the JFrame. This is different than java.awt.Frame, e.g. to add a child to an AWT Frame you'd write:        frame.add(child);
 However using JFrame you need to add the child to the JFrames contentPane instead: 
       frame.getContentPane().add(child);
 The same is true for setting LayoutManagers, removing components, listing children, etc. All these methods should normally be sent to the contentPane() instead of the JFrame itself. The contentPane() will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default contentPane() will have a BorderLayout manager set on it. 
Please see the JRootPane documentation for a complete description of the contentPane, glassPane, and layeredPane properties.