Make Frames Resize Dynamically #100
Chapter 12, Miscellany
|
501
HACK
A Word About Speed
When you have dynamic layout turned on, the window will repaint each
time the user moves the mouse. This will make the application feel respon-
sive because there is always information on the screen being updated. If your
frame contains an animated component, it will continue to play while the
user resizes the window.
The disadvantage of dynamic layout is that a resize will generate a whole lot
of repaint requests in a very short time. Even if the user moves the window
just one pixel, it will trigger a repaint on the entire frame (unlike scrolling,
which usually requires just repainting a strip at the bottom). If your paint-
ing code is slow (or you have a lot of components on screen), then the
dynamic layout could actually make your program feel slower. Be sure you
make your painting as fast as possible, perhaps skipping some of the more
complicated effects during the resize. You may also want to use dynamic lay-
out only in a program with a small streamlined window, such as a media
player or utility app.

Get Swing Hacks 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.