开发者

What's the difference between the root pane and the top-level container, in Swing?

I understand that every top level container has some layers:

开发者_如何学JAVA

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!


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

What's the difference between the root pane and the top-level container, in Swing?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜