Java JRootPane Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 classJRootPane(): It creates a JRootPane(), It setting up it's layeredPane, contentPane and glassPane Most used Methods of this classMethods 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 JRootPaneExample 1: Java // Java Program to Implement a JRootPane including creating // a JFrame with a content pane, a menu bar, a glass pane, // and a layered pane import javax.swing.*; public class RootPaneExample { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame frame = new JFrame("JRootPane Example"); JRootPane rootPane = frame.getRootPane(); // Step 1: Create a content pane JPanel contentPane = new JPanel(); contentPane.add( new JLabel("GeeksforGeeks")); // Step 2: Create a menu bar JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); fileMenu.add(openItem); menuBar.add(fileMenu); // Step 3: Create and add a glass pane JPanel glassPane = new JPanel(); // Make it transparent glassPane.setOpaque(false); // Step 4: Create a layered pane and add // components JLayeredPane layeredPane = rootPane.getLayeredPane(); JLabel label1 = new JLabel("Label 1"); JLabel label2 = new JLabel("Label 2"); layeredPane.add(label1, JLayeredPane.DEFAULT_LAYER); layeredPane.add(label2, JLayeredPane.PALETTE_LAYER); // Set the content pane, menu bar, and glass // pane rootPane.setContentPane(contentPane); rootPane.setJMenuBar(menuBar); rootPane.setGlassPane(glassPane); frame.setSize(300, 200); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } } Output: Example 2: Java // Java Program to Implement setContentPane and setJMenuBar // methods with JRootPane import javax.swing.*; // Driver Class public class JRootPaneExample { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // Create a JFrame JFrame frame = new JFrame("JRootPane Example"); JRootPane rootPane = frame.getRootPane(); // Step 1: Create a content pane and set it JPanel contentPane = new JPanel(); JLabel label = new JLabel("Welcome to GFG"); contentPane.add(label); rootPane.setContentPane(contentPane); // Step 2: Create a menu bar and set it JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); JMenuItem exitItem = new JMenuItem("Exit"); fileMenu.add(openItem); fileMenu.add(exitItem); menuBar.add(fileMenu); rootPane.setJMenuBar(menuBar); // Make the frame visible and configure it frame.setSize(400, 200); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }); } } Output: Comment More infoAdvertise with us Next Article Java JTextPane C chinmaya121221 Follow Improve Article Tags : Java Geeks Premier League java-swing Geeks Premier League 2023 Practice Tags : Java Similar Reads Java JOptionPane In Java, JOptionPane is a part of the Java Swing library. It helps us to create dialog boxes such as message dialogs, conformation dialogs, input dialogs, and options dialogs In this article, we are going to explore some constructors, methods, and some examples of JOptionPane. Constructors of JOptio 5 min read Java JScrollPane Java JScrollPane is a component in the Java Swing library that provides a scrollable view of another component, usually a JPanel or a JTextArea. it provides a scrolling functionality to the display for which the size changes dynamically. It is useful to display the content which exceeds the visible 3 min read Java JTextPane In Java, JTextPane is a versatile component that is part of the Swing library for building graphical user interfaces. It extends JEditorPane and provides an editable text component with rich text formatting capabilities. JTextPane allows you to display and edit styled text, making it suitable for im 3 min read Java JTabbedPane JTabbedPane is a GUI(Graphical User Interface) component in the Java Swing library that allows you to create a tabbed pane interface. A tabbed pane is a container that can store and organize multiple components into distinct tabs. It contains a collection of tabs. When you click on a tab, only data 5 min read Java JEditorPane A JEditorPane is a component in Java Swing that provides a simple way to display and edit HTML and RTF (Rich Text Format) content. It is a versatile component that allows you to display styled text, links, and images, making it useful for creating simple web browsers, rich-text editors, and content 3 min read Java JFrame Thе Java JFramе is an essential componеnt of Java Swing, which is a part of thе Java SWT(Standard Widgеt Toolkit). JFrame in Java is a class that allows you to crеatе and manage a top-lеvеl window in a Java application. It sеrvеs as thе main window for GUI-basеd Java applications and providеs a plat 4 min read Like