开发者

What is the difference between JFrame.getContentPane() and JFrame.getRootPane()?

What is the difference between Java frame functions getContentPane() and getRootPane()? Also开发者_如何学C what wil happen when we set a JButton as Default.


from documentation:

getContentPane() is generally implemented like this:

public Container getContentPane() {
    return getRootPane().getContentPane();
}

It's well described in Swing tutorial (here).

What is the difference between JFrame.getContentPane() and JFrame.getRootPane()?


While using top-level containers in AWT or Swing, the root pane is the base pane.

The hierarchy is as follows:

  1. Glass Pane: Generally hidden, setting to visible will show up a glass cover over the root pane areas.
  2. Layered Pane: Contains the Menubar and the Content Pane
  3. 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.

By setting Jbutton default, What are you exactly trying to accomplish?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜