Chapter10: java.awt package-Layout
-
A Layout Manager is responsible
for positioning and sizing the individual components in that container.
-
A Layout Manager is any
class that implements the LayoutManager interface.
-
There are 5 abstract methods:
- addLayoutComponent()
- layoutContainer()
- minimumLayoutsize()
- preferedLayoutsize()
- removeLayoutComponent()
-
Instead of invoking the
layout manager's methods yourself, Java's default container methods
invoke them for you at the appropriate times.These container methods
include add(), getMinimumSize(), getPreferredSize(), remove() and
removeAll().
- Containers and Layout Managers work in
partnership.The Layout Manager generally controls where a component
is positioned.a container will control the default font for its components.
- The types of Layout Manager's of exam concern
are
FlowLayout, BorderLayout, GridLayout, GridBagLayout
- GridLayout class:This is one of the simpler
Layout Manager class.It attempts to fit the component objects into
a rectangular grid.
- Subdivides its territory into a matrix
of rows and columns.The number of rows and columns are specified as
parameters.
- Every component has a preferred size.
- GridLayout always ignores components preferred
size.
- If no arguments are given,it takes the
full frame and displays the components.All components within the frame
are the same width and height.
- Each cell in the grid is the same height
as other cells and each width is the same as the other cells.Components
are stretched both horizontally and vertically to fill the cell.
- Components are added to the grid left to
right and top to bottom.If more components are added than there are
columns,the Grid Layout keeps the same number of rows but adds the
necessary number of columns .
- Border Layout:Default for Frames,window
or Dialog
- Divides the territory into five regions
as North, South, East, West and Center. Each region contains a single
component.
- The default is the the center of the layout
area.
- Components are rarely allowed to be their
preferred size in a BorderLayout.
- BorderLayout streches"North"
and "South" components horizontally,"East" and
"West" components vertically and "Center" components
both horizontally and vertically.
- If nothing is placed in "East"
or "West" then the "Center" stretches all the
way from the left edge to the right edge.
- Button, Label, TextField are streachable
where as check box is not.
- Flow Layout Manager: Default for Panels
and Applets.
- A flow layout arranges components in a
left- to-right flow,much like lines of text in a paragraph.
- Flow layout are typically used to arrange
buttons in a panel.It will arrange buttons left to right until no
more buttons fit on the same line.Each line is centered.
- You can specify the direction by
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
|
©Copyrights anilbachi.8m.com
All rights reserved
|
|