12.2 BorderLayout



This layout manager has the concept of four border regions and a center area. When you add something to a panel that's using a BorderLayout you must use an add( ) method that takes a String object as its first argument, and that string must specify (with proper capitalization) "North" (top), "South" (bottom), "East" (right), "West" (left), or "Center".  If you misspell or mis-capitalize, you won't get a compile-time error, but the applet simply won't do what you expect. Fortunately, as you will see shortly, there's a much-improved approach in Java 1.1.

Case Study: BorderLayout1.java


For every placement but "Center", the element that you add is compressed to fit in the smallest amount of space along one dimension while it is stretched to the maximum along the other dimension. "Center", however, spreads out along both dimensions to occupy the middle.

The BorderLayout is the default layout manager for applications and dialogs.


Next Page