Java Reference
In-Depth Information
simple as that. You don't add the components for your application or applet GUI directly to the JFrame or
JApplet object for your program. Let's look at how it actually works in practice.
Window Panes
When you want to add GUI components or draw in a window displayed from a JFrame object, you add the
components to, or draw on, a window pane that is managed by the JFrame object. The same goes for an
applet. Broadly speaking, window panes are container objects that represent an area of a window, and they
come in several different types.
You use a window pane called the content pane most of the time, but there are others. The relationship
between the contentPane object, other window panes, and the application window itself is shown in Figure
17-7 .
FIGURE 17-7
As you see, the area below the title bar in a JFrame window corresponds to a JRootPane object. This
contains another pane, the layeredPane object in the illustration, which is of type JLayeredPane . This
pane corresponds to the whole of the area occupied by the JRootPane object in the window and manages
the menu bar if the window has one. The area in the layeredPane below the menu bar corresponds to the
contentPane object, and it's here that you typically add GUI components. You also display text or do any
drawing in the area covered by the content pane.
The layeredPane object has special properties for advanced applications that permit groups of compon-
ents to be managed in separate layers that overlay one another within the pane. With this capability you can
control how components are displayed relative to one another, because the layers are displayed in a particu-
lar order from back to front. The components in a layer at the front appear on the screen in front of those in
a layer that is towards the back.
There is also an additional pane not shown in Figure 17-7 . This is the glassPane object, which also cor-
responds to the complete JRootPane area. The contents of the glassPane object displays on top of all the
other panes, so this is used to display components that you always want to display on top of anything else
displayed in the window — such as drop-down menus. You can also use the glassPane object to display
 
 
Search WWH ::




Custom Search