Workshop: Laying Out an Application

The layout managers you have seen thus far were applied to an entire frame; the setLayout() method of the frame was used, and all components followed the same rules. This setup can be suitable for some programs, but as you try to develop a graphical user interface with Swing and the Abstract Windowing Toolkit, you often will find that none of the layout managers fit.

One way around this problem is to use a group of JPanel objects as containers to hold different parts of a graphical user interface. You can set up different layout rules for each of these parts by using the setLayout() methods of each JPanel. Once these panels contain all of the components they need to contain, the panels can be added directly ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH 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.