INTRODUCTION Java uses Layout Managers to define the location and size of Graphical User Interface components. Java technology uses Layout Managers to define the location and size of Graphical User Interface components.. A Layout Manager implements a layout policy that defines constraints between components in a container.
TYPES OF LAYOUT MANAGERJava technology provides the following LayoutManagers, each of which implements the LayoutManager interface: Flow Layout Grid Layout Border Layout CardLayout
DEFAULT LAYOUT MANAGER The FlowLayout is the default Layout Manager for Panel, and hence the Applet class. The BorderLayout is the default Layout Manager for Window class and its subclasses (Frame and Dialog).
SETTING LAYOUT MANAGERS The following method defined in the Container class can be used for setting layout managers. void setLayout(LayoutManager mgr);
FLOWLAYOUT MANAGER FlowLayout places component in rows from left to right. Components towards the end of row are written on next row, if there is not enough space in the current row. The FlowLayout honors the specified size of a component.
CONTD…. The following constructors of FlowLayout are provided by AWT – FlowLayout(); FlowLayout(int alignment); FlowLayout(int alignment, int hor_gap, int ver_gap);
GRIDLAYOUT MANAGER A Grid Layout Manager places the components in a rectangular grid. Each components position is identified by a column and row. All the cells in the grid have same size and width. Each component is stretched to the cell size. So a Grid Layout ignores the Components preferred size.
CONTD….The GridLayout class provides the followingconstructors: GridLayout(); GridLayout(int rows, int columns); GridLayout(int rows, int columns, int hor_gap, int ver_gap);
BORDERLAYOUT MANAGER A BorderLayout Manager divides the window into five regions - North, East, West, South and Center. A component can be explicitly added to one of the regions using the add() method of the Container class. Any space left over by the component in North, East, South and West is occupied by the component in Center.
CONTD: The BorderLayout class defines the following constructors : BorderLayout(); BorderLayout(int hor_gap, int ver_gap);
CARD LAYOUT The CardLayout class is unique among the other layout managers in that it stores several different layouts. Each layout can be thought of as being on a separate index card in a deck that can be shuffled so that any card is on top at a given time.
CARD LAYOUTCardLayout provides these two constructors: CardLayout( ) CardLayout(int horz, int vert)