Figure 7-11. Using panes to architect a GUI.
Container classes that support panes store a single JRootPane instance. This in-
stance stores a JLayeredPane instance and a Component instance that serves as
the glass pane. The JLayeredPane instance stores a javax.swing.JMenuBar
instance and a Container subclass instance that serves as the content pane.
The following example demonstrates how you might create a frame window with a
JFrame f = new JFrame();
JRootPane rp = f.getRootPane();
Container cp = rp.getContentPane();
cp.add(new JButton("Ok")); // Add the button to the frame's
Container classes that support panes implement the
javax.swing.RootPaneContainer interface, which provides convenience
methods for accessing the root pane and setting/getting the content, glass, and layered
panes.Forexample, RootPaneContainer 's Container getContentPane()
method behaves as if you called getRootPane().getContentPane() . It lets
you shorten the previous example to the following: