Lightweight Components
Chapter: Swing Introduction
...Section: Sequences of pictures in rapid succession
... ...Subsection: Lightweight Components
This material comes from Sun.
A heavyweight component is one that is associated with its own native
screen resource (commonly known as a peer). A lightweight component is
one that "borrows" the screen resource of an ancestor (which means it
has no native resource of its own -- so it's "lighter").
Some of the benefits of using Swing components are:
- More efficient use of resources: Lightweight components are really "lighter" than heavyweight components.
- More consistency across platforms because Swing is written entirely in Java.
- Cleaner look-and-feel integration: You can give a set of components a matching look-and-feel by implementing them using Swing.
The main differences between heavyweight and lightweight are:
- A lightweight component can have transparent pixels; a heavyweight is always opaque.
- A lightweight component can appear to be non-rectangular because of its ability to set transparent areas; a heavyweight can only be rectangular.
- Mouse events on a lightweight component fall through to its parent; mouse events on a heavyweight component do not fall through to its parent.
- When a lightweight component overlaps a heavyweight component, the heavyweight component is always on top, regardless of the relative z-order of the two components.
For more details, read this article.