
Double-Buffering
Double-buf fering is the process of drawing graphics into an off-scr een image
buf fer and then copying the contents of the buffer to the screen all at once. For
complex graphics, using double-buffering can reduce flickering. Swing automati-
cally supports double-buffering for all of its components. To enable it, simply call
the
setDoubleBuffered() method (inherited from JComponent)toset the double-
Buffered pr operty to true for any components that should use double-buffer ed
drawing.
Remember that double-buffering is memory intensive. Its use is typically only justi-
fied for components that are repainted very frequently or have particularly com-
plex graphics to display. Note, however, that if a container uses double-buffering,
any double-buffer ed childr en it has share the off-scr een buf fer of the container, so
the requir ed of f-screen buffer is never larger than the on-screen size of the appli-
cation.
TheBox Container
Chapter 2, Swing and AWT Architectur e, discussed the general task of arranging
components within containers and listed the layout managers provided by AWT
and Swing. This section describes a commonly used Swing layout management
technique in detail. The easiest way to create complex arrangements of Swing
components is often with the
javax.swing.Box container.
*
Box arranges its compo-
nents into a single row or a single column. You can then use nested
Box contain- ...