Java Reference
In-Depth Information
figure 11-10  
How It Works
This is how it works:
1.
This class is similar to the previous one, but now a BorderLayout object is specified as the layout
manager. This step is optional in the case of a JFrame container, because its default layout man-
ager is already BorderLayout .
2.
Components are now added to a specific position by specifying the location as the second argument
of the add method.
3.
Try resizing the window and see how the controls behave. Try removing a few of the buttons and
see how the window reacts, as shown in Figure 11-11.
figure 11-11  
4.
Try adding a call to setPreferredSize for one of the buttons. What happens? As you can
see, BorderLayout has its own ideas about sizing components and does not adhere to your
size hints. This does make the layout manager well suited to host nested JPanels , however
(which then can be given their own separate layout manager in which you can lay out all
components).
gridlayout
A GridLayout layout manager places components, as the name suggests, in a grid of cells. Each
component will take up all the available space in its cell, and the dimensions of each cell are the
same. When resizing containers with a GridLayout layout manager, the width and height of each
cell will be resized accordingly.
 
Search WWH ::




Custom Search