Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

HOME

java certification tutorial

chapter1 | chapter2 | chapter3 | chapter4 | chapter5 | chapter6 |

chapter7 | chapter8 | chapter9 | chapter10 | chapter11 |

 

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:
  1. addLayoutComponent()
  2. layoutContainer()
  3. minimumLayoutsize()
  4. preferedLayoutsize()
  5. 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

  • The FlowLayout layout manager is the only layout manager which allows components to be their preferred size.
  • If a container using a FlowLayout is resized,all of the components inside it might need to be arranged,and some might not be comletely visible.
  • GridBagLayout:GridBagLayout class is a flexible layout manager that aligns components vertically and horizontal.without required that the components be of the same size.
  • Each GridBagLayout object maintains a dynamic rectangular grid of cells with each component occupying one or more cells called its display area.
  • Unlike GridLayout the sizes of the grids do not need to be constant and a component can occupy more(or less) than one row or column.

 

 

 

 

 

 

 

©Copyrights anilbachi.8m.com

All rights reserved