Hi,
in the first approach you will have container (contentPane) and in this you will put another container (JPanel). In the second approach you will replace the default contentPane by your new contentPane (JPanel).
The structure can be seen in this tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html
L.P.
First of all, my question still remains - is there any practical difference?
> In the second approach you will replace the default contentPane by your new contentPane (JPanel).
I wasn't aware that a JPanel was a top-level container with a content pane.
What am I missing?
In the first approach, you will be ADDING the panel to the current ConentPane as specified by your layout. In the second, you completely replace the panel.
Practically, this will differ if you 1) have some layout that displays both panels, and 2) the garbage collector will never destoy the current content pane which you would like to override as it is still containing active elements (i.e. the panel you added).
Message was edited by:
jeffus
> is there any practical difference?
No, except maybe the LayoutManager. By default the JPanel of the content pane uses a BorderLayout. By default a JPanel uses a FlowLayout.
If you think you need to access the content pane as a JPanel then just create your own variable:
JPanel contentPane = (JPanel)frame.getContentPane().