Credits

Monday, February 21, 2011

Java's Layout Managers

Layout Managers are used to control the placement and size of components inside a container like a Frame or Panel. Since we have container inside a container, we can also embed layout manager inside another layout manager.

In Panel, the default layout is a FlowLayout where components are centered horizontally, so, a programmer can automatically arrange the components with the same sizes.   On the other hand, contentPanes have BorderLayout as their default layout where regions are used to hold components and/or containers.

In Java, the following are the layout managers:

  •  BorderLayout  - makes use of regions - NORTH, SOUTH, WEST, EAST, CENTER;
  • FlowLayout -  moves the components left to right and automatically wraps components;
  • GridLayout - use this if you want to see components in rows and in columns where components are of the same size;
  • CardLayout - this layout manager allows you to see only one component at a time;
  • BoxLayout - this layout allows you to see components in a row or  in a column;
  • GridBagLayout - allows the control of size, placement and alignment constraints of each component. 
  •  

AddThis