Swing 中根窗格和顶级容器有什么区别?

发布于 2024-09-01 19:55:59 字数 219 浏览 2 评论 0原文

我知道每个顶级容器都有一些层:

根窗格
图层面板
内容窗格
玻璃板

,但我不明白根窗格本身是否是顶层容器。

窗格和容器之间有什么关系?事实上,当我返回一个窗格时 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 with
getContentPane(), the object is of type Container!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

电影里的梦 2024-09-08 19:55:59

您还有一个 JFrame。详细了解如何使用根窗格

RootPaneContainer
来自 JRootPane

“重量级”组件(委托给对等方或主机系统上的本机组件的组件)以较暗、较重的框显示。显示了四个重量级 JFC/Swing 容器(JFrame、JDialog、JWindow 和 JApplet)与其扩展的 AWT 类的关系。这四个组件是 Swing 库中唯一的重量级容器。

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.

神也荒唐 2024-09-08 19:55:59

如果您查看之前的答案或链接,您会发现,问题的实际答案是:

根窗格不是顶级容器本身,而是顶级容器一个根窗格。

由于所有 Swing 顶级容器(即 JFrameJDialogJApplet)都实现 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文