VOOZH about

URL: https://www.geeksforgeeks.org/java/java-jrootpane/

⇱ Java JRootPane - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java JRootPane

Last Updated : 28 Apr, 2025

In Java Swing, JRootPane is a fundamental component that serves as the root container for creating complex user interfaces. It encapsulates the core functionality of a top-level window, like JFrame, and provides a structure for organizing the content within a GUI application. In Java JRootPane is a part of javax.swing package. It does not contain any constructor it has only the default constructor.

Default constructor of this class

JRootPane(): It creates a JRootPane(), It setting up it's layeredPane, contentPane and glassPane

Most used Methods of this class

Methods

Description

setContentPane(Container content)

This method allows you to set the content pane of the JRootPane.

setJMenuBar(JMenuBar menu)

Used to set the menu bar for the JRootPane.

setGlassPane(Component glass)

You can use this method to set the glass pane, which is typically an invisible layer used for custom painting, event handling, or overlaying the entire root pane.

getLayeredPane()

Returns the JLayeredPane that allows you to work with multiple layers within the root pane.

getContentPane()

Returns the content pane currently set in the JRootPane.

getJMenuBar()

Retrieves the menu bar associated with the JRootPane.

getGlassPane()

Retrieves the current glass pane.

setDefaultButton(JButton defaultButton)

Sets the default button for the root pane, which is the button that responds to the "Enter" keypress.

getDefaultButton()

Retrieves the default button currently set in the root pane.

Following are the programs to implement JRootPane

Example 1:

Output:

👁 Java JRootPane

Example 2:

Comment