The issue of lightweight versus heavyweight components has complicated Swing since its inception. The concept of lightweight components managed entirely by Java code is, of course, one of the major benefits introduced by Swing. What has confused the majority of programmers from the start is the issue of z-order, or layering, between Swing lightweight components and AWT heavyweight components.
In Swing, it might help to think of a heavyweight component as
an artist’s easel. Top-level components in Swing (
JFrame) are heavyweight, while everything
else isn’t. Lightweight components added to those top-level
heavyweights can be thought of as drawings on the canvas of each
easel. Therefore, if another heavyweight component (another easel) is
moved in front of the original easel, or even attached to it, the
lightweight paintings on the original easel are obscured. Figure 28-6 demonstrates this
Figure 28-6. Consider heavyweight components as easels and lightweight components as drawings
The same is true for how Swing interprets the z-order of lightweight and heavyweight components, even in a container. If a heavyweight component is added to a container that has lightweight components, the heavyweight is always on top; the lightweight components must share the same z-order as the parent ...