Lightweights and Preferred Sizes

Preferred sizes for heavyweight components are is calculated by the component's peer, whereas the preferred size for heavyweight containers are is calculated by the container's layout manager.

On the other hand, by default, a one-pixel square is the value for preferred sizes for lightweight components, by default, is a one-pixel square. As a result, lightweight components should override getPreferredSize() to ensure that they are sized according to their preference. Of course, overriding preferredSize() does not guarantee that the lightweight will be sized according to the dimension returned from preferredSize() because the shape of both heavyweight and lightweight components depends upon the layout manager that ...

Get Graphic Java™ 1.2, Volume I: AWT, Third 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.