java JFrame.getContentPane() 和 JFrame.getRootPane() 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7361980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between JFrame.getContentPane() and JFrame.getRootPane()?
提问by Ajay Yadav
What is the difference between Java frame functions getContentPane()
and getRootPane()
?
Also what wil happen when we set a JButton as Default.
Java 框架函数getContentPane()
和getRootPane()
? 当我们将 JButton 设置为默认值时会发生什么。
采纳答案by jagbandhuster
While using top-level containers in AWT or Swing, the root pane is the base pane.
在 AWT 或 Swing 中使用顶级容器时,根窗格是基础窗格。
The hierarchy is as follows:
层次结构如下:
- Glass Pane: Generally hidden, setting to visible will show up a glass cover over the root pane areas.
- Layered Pane: Contains the Menubar and the Content Pane
- Content Pane: Is the basic layout pane in which components are actually placed.
- 玻璃窗格:通常隐藏,设置为可见将在根窗格区域上显示玻璃盖。
- 分层窗格:包含菜单栏和内容窗格
- 内容窗格:是实际放置组件的基本布局窗格。
Calling the method getRootPane()
will return the reference to the base pane, while calling the getContentPane()
method will get you the reference to the Content Pane. It is visible by default.
调用该方法getRootPane()
将返回对基本窗格的引用,而调用该getContentPane()
方法将获得对内容窗格的引用。默认情况下它是可见的。
By setting Jbutton default, What are you exactly trying to accomplish?
通过将 Jbutton 设置为默认值,您究竟想完成什么?
回答by Micha? ?rajer
from documentation:
从文档:
getContentPane() is generally implemented like this:
public Container getContentPane() { return getRootPane().getContentPane(); }
getContentPane() 通常是这样实现的:
public Container getContentPane() { return getRootPane().getContentPane(); }
It's well described in Swing tutorial (here).
它在 Swing 教程(这里)中有很好的描述。
回答by Dragon8
The Root Pane, as the name implies, is the root of the frame/window/dialog.
顾名思义,根窗格是框架/窗口/对话框的根。
Its contains als other components of this top-level component. the content pane is one of the four parts of the root pane and contains the components. the other parts of the root pane are glass pane, layered pane and a optional menu bar.
它包含此顶级组件的其他组件。内容窗格是根窗格的四个部分之一,包含组件。根窗格的其他部分是玻璃窗格、分层窗格和可选的菜单栏。
the tutorials at oracle explains this really good: http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html
oracle 的教程很好地解释了这一点:http: //download.oracle.com/javase/tutorial/uiswing/components/rootpane.html