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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.