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

What is the difference between the Java frame functions getContentPane() and getRootPane() ? Also, what happens when we set JButton as Default.

+7
source share
3 answers

When using top-level containers in AWT or Swing, the root panel is the base panel.

The hierarchy is as follows:

  • Glass panel: usually hidden, the adjustment to the visible surface will be displayed on the lid above the panel areas.
  • Layered panel: contains a menu bar and a content panel
  • Content Panel It is the basic layout panel on which the components are actually located.

A call to the getRootPane() method will return a link to the base panel, while a call to the getContentPane() method will provide you with a link to the content panel. This is visible by default.

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

+4
source

from the documentation :

getContentPane () is usually implemented as follows:

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

This is well described in the Swing tutorial ( here ).

enter image description here

+11
source

The root panel, as the name implies, is the root of the frame / window / dialog window.

It contains other components of this top-level component. the content panel is one of the four parts of the root panel and contains components. other parts of the root panel are a glass panel, a multi-level panel, and an additional menu bar.

the oracle tutorials explain this very well: http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html

0
source

All Articles