Java Reference
In-Depth Information
CNorth
C1
C2
C3
C1
C2
C3
CCenter
C4
C5
Empty
C4
C5
CSouth
(a)
(b)
(c)
Figure 2.5 Three layout managers. (a) The arrangement of the components in a border lay-
out. (b) The row-wise arrangement of the embedded components. The dashed lines indicate
the upper and lower boundaries of the rows. The height of each row is individually deter-
mined by the height of the tallest component in it. The spacing between the components
and between the rows can be modified. (c) A 2
3 grid layout into which five components
are embedded. All columns and rows are equally wide and high.
×
runtime by checking all components in the row. See Figure 2.5b. Here are some
constructors of FlowLayout :
FlowLayout()
Flowlayout( int align)
Flowlayout( int align, int hdist, int vdist)
The first constructor generates a layout which by default has five pixels between
the components in a row and five pixels between the rows. In addition, the second
constructor specifies the alignment of the components, where align is one of
FlowLayout.RIGHT, FlowLayout.LEFT, FlowLayout.CENTER
This determines whether the components in every row are 'packed' to the right, the
left or whether they are centred. The third constructor also specifies the horizontal
distance hdist between the components in a row and the vertical distance vdist
between rows. Program LayoutDriver shows some examples.
The size of the
!
components for which we did not define dimensions are set to default minimum
values; these are 10
10 on most systems.
The layout manager for a component comp recomputes the layout every time
the component comp is redrawn, especially after a resizing of comp .Ifafter resizing
×
!
more or fewer components fit into a row then they are newly arranged. Try it in
LayoutDriver . See also Figure 2.5.
The third layout manager described here is the GridLayout which orders the
components in a grid. The parent component (the content pane in our example) is
divided into r
c rectangular cells , where c is the number of cells per row and r is
the number of rows. All cells have the same size. The components are embedded
×
!
into the cells row-wise from left to right. If there are more cells than embedded
!
components the layout manager tries to fill all rows as far as possible and might
generate fewer than c columns! If there are fewer cells than components then
columns are added. Basically the grid layout manager ignores the column number.
In order to have a fixed number c
>
0ofcolumns, the row number must be set to
r
=
0 and the column number to c . Then there will always be c columns and the
Search WWH ::




Custom Search