The Root Pane

Now that we’ve seen the simplest example of a Swing container, we’ll move on to something a bit more powerful. Most of the other Swing containers (JFrame, JApplet, JWindow, JDialog, and even JInternalFrame) contain an instance of another class, JRootPane , as their only component, and implement a common interface, RootPaneContainer . In this section, we’ll look at JRootPane and RootPaneContainer, as well as another class JRootPane uses, JLayeredPane .

Before jumping into the descriptions of these classes, let’s take a look at how the classes and interfaces that make up the Swing root containers fit together. Figure 8-2 shows that JApplet, JFrame, JDialog, and JWindow do not extend JComponent as the other Swing components do. Instead, they extend their AWT counterparts, serving as top-level user interface windows. This implies that these components (unlike the lightweight Swing components) have native AWT peer objects.

Swing “root” container class diagram

Figure 8-2. Swing “root” container class diagram

Notice that these Swing containers (as well as JInternalFrame) implement a common interface, RootPaneContainer . This interface gives access to the JRootPane’s properties. Furthermore, each of the five containers uses a JRootPane as the “true” container of child components managed by the container. This class is discussed later in this chapter.

The JRootPane Class

JRootPane is a special container that extends ...

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.