Monday, July 29, 2013


FlowLayout is one of layout managers that arranges and resizes the components placed on the window in a directional flow. The components flow  in the same way as the flow of characters in a line of text in a paragraph.

FlowLayout class has three constructors as shown below.
creates a new flow layout with center alignment and a 5-pixcel space between the components.
-FlowLayout(int alignment)
creates a new flow layout with specified alignment. The value of the alignment can be FlowLayout.LEFT, FlowLayout.RIGHT, or FlowLayout.CENTER.
-FlowLayout(int alignment, int hor, int ver)
creates a new flow layout with specified alignment, horizontal and vertical spaces between components.

import java.awt.Button;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

class InterfaceShow extends Frame{
InterfaceShow(String title){
setLayout(new FlowLayout(FlowLayout.LEFT));
setSize(new Dimension(500,300));


addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){

for(int i='A';i<='Z';i++){
char c=(char)i;
add(new Button(c+""));

public class AWTControls {
public static void main(String[] args){
new InterfaceShow("Using FlowLayout");


flowlayout layoutmanager


  1. Hi, i need a layout manager that can manager different sizes of components on Frame or Frame window. For example, the first row, i will place one text box. The second row contains list, text area, and two buttons. However, i don't want to want the two buttons to be resized automatically to become big as the list and text area. How can i do? Please suggest a good solution. Thanks

  2. To solve your problem, you will use the GridBagLayout layout manager. It is more complex than GridLayout. However, it more flexible.