5

I understand that every top level container has some layers:

root pane
layer pane
content pane
glass pane

but I don't understand whether the root pane is the top level container itself.

What is the relationship between a pane and a container? In fact, when I return a pane with getContentPane(), the object is of type Container!

Pops
  • 30,199
  • 37
  • 136
  • 151
xdevel2000
  • 20,780
  • 41
  • 129
  • 196

2 Answers2

3

You also have a JFrame. Read more on How to Use Root Panes.

RootPaneContainer From JRootPane:

The "heavyweight" components (those that delegate to a peer, or native component on the host system) are shown with a darker, heavier box. The four heavyweight JFC/Swing containers (JFrame, JDialog, JWindow, and JApplet) are shown in relation to the AWT classes they extend. These four components are the only heavyweight containers in the Swing library.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jonas
  • 121,568
  • 97
  • 310
  • 388
2

If you take a look at the previous answers or links, you will find out, between the lines, that the actual answer to the question is:

The root pane IS NOT the top-level container itself, but the top-level container HAS a root pane.

Since all Swing top-level containers (namely, JFrame, JDialog and JApplet) implement the RootPaneContainer interface, this means that you can gain access to their root pane in a general way (no need to check if this is a JFrame or JDialog....)

About the second part of the question, the difference between pane and container, actually there is no difference, a pane is a java.awt.Container (or any subclass, in particular javax.swing.JPanel).

What is important to udnerstand is the various panes that exist in a Swing top-level container (root, content, glass, layered), for this you have to take a look at the links posted in previous answers.

Pops
  • 30,199
  • 37
  • 136
  • 151
jfpoilpret
  • 10,449
  • 2
  • 28
  • 32
  • -1; `JInternalFrame` is not a top-level container, [it just plays one on TV](http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html). – Pops Feb 04 '11 at 19:02
  • On second thought, since this is pretty cut-and-dried, I'm going to remove that bit and un-downvote the answer; please comment if you're against this. – Pops Feb 04 '11 at 19:09
  • You're right, Lord Torgamus; I'm fine with your edit of my answer. Thanks. – jfpoilpret Feb 09 '11 at 09:28