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 GUI with Swing, you often 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 GUI. You can set up different layout rules for each of these parts by using the setLayout()
methods of each JPanel
. After these panels contain all the components they need to contain, you can add the panels directly to the frame.
The next project develops a full interface for the program you write during the ...
Get Sams Teach Yourself Java™ in 24 Hours, Sixth 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.