What is the difference between Java frame functions getContentPane()
and getRootPane()
?
Also what wil happen when we set a JButton as Default.
The getContentPane() method retrieves the content pane layer so that you can add an object to it. The content pane is an object created by the Java run time environment. You do not have to know the name of the content pane to use it.
getRootPane() Return this component's single JRootPane child. void. setContentPane(Container contentPane) The "contentPane" is the primary container for application specific components.
JFrame is a top-level container that provides a window on the screen. A frame is actually a base window on which other components rely, namely the menu bar, panels, labels, text fields, buttons, etc. Almost every other Swing application starts with the JFrame window.
setDefaultCloseOperation() EXIT_ON_CLOSE — Exit the application. JFrame. HIDE_ON_CLOSE — Hide the frame, but keep the application running. JFrame. DISPOSE_ON_CLOSE — Dispose of the frame object, but keep the application running.
from documentation:
getContentPane() is generally implemented like this:
public Container getContentPane() { return getRootPane().getContentPane(); }
It's well described in Swing tutorial (here).
While using top-level containers in AWT or Swing, the root pane is the base pane.
The hierarchy is as follows:
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With