Forcing a Container to Lay Out Its Components
It is not uncommon for situations to arise where it is necessary to force a container to lay out its components. Since the recipe for programmatically forcing a layout is not readily apparent, we'll take some time to explore the issue here.
Figure 10-5 shows an applet that contains a panel with a textfield and two buttons for adjusting the textfield's font size—the applet itself is listed in Example 10-3.
Figure 10-5. ValidateApplet. The buttons adjust the size of the textfield's font. After the font size is adjusted, the applet needs to be laid out in order for the textfield and its container to resize to accommodate the new font size.
Example 10-3. ValidateApplet Class Listing
import java.applet.Applet; ... |
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.