Swing 中根窗格和顶级容器有什么区别?
我知道每个顶级容器都有一些层:
根窗格
图层面板
内容窗格
玻璃板
,但我不明白根窗格本身是否是顶层容器。
窗格和容器之间有什么关系?事实上,当我返回一个窗格时 getContentPane()
,该对象的类型为Container
!
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 withgetContentPane()
, the object is of type Container
!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还有一个
JFrame
。详细了解如何使用根窗格。来自 JRootPane:
You also have a
JFrame
. Read more on How to Use Root Panes.From JRootPane:
如果您查看之前的答案或链接,您会发现,问题的实际答案是:
根窗格不是顶级容器本身,而是顶级容器有一个根窗格。
由于所有 Swing 顶级容器(即
JFrame
、JDialog
和JApplet
)都实现RootPaneContainer
接口,因此 通用方式访问其根窗格(无需检查这是JFrame
还是JDialog
....)意味着您可以以 问题,窗格和容器之间的区别,实际上没有区别,窗格是一个 java.awt.Container(或任何子类,特别是 javax.swing.JPanel) >)。
对于理解来说,重要的是 Swing 顶级容器中存在的各种窗格(根、内容、玻璃、分层),为此您必须查看之前答案中发布的链接。
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
andJApplet
) implement theRootPaneContainer
interface, this means that you can gain access to their root pane in a general way (no need to check if this is aJFrame
orJDialog
....)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 particularjavax.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.