The Root Pane

The JRootPane Class

JRootPane is a special container that extends JComponent and is used by many of the other Swing containers. It’s quite different from most containers you’re probably used to using. The first thing to understand about JRootPane is that it contains a fixed set of components: a Component called the glass pane and a JLayeredPane called, logically enough, the layered pane. Furthermore, the layered pane contains two more components: a JMenuBar and a Container called the content pane.

import javax.swing.*;
import java.awt.*;

public class RootExample {
	public static void main(String[] args) {
		JFrame f = new JFrame();
		JRootPane root = f.getRootPane(); // XXX Pay attention to these
		Container content = root.getContentPane(); // XXX lines. They are
		content.add(new JButton("Hello")); // XXX explained below.