All for Joomla All for Webmasters

FlowLayout

The FlowLayout is used to arrange the components in a line, one after another (in a flow). It is the default layout of applet or panel.

Fields of FlowLayout class:

  1. public static final int LEFT
  2. public static final int RIGHT
  3. public static final int CENTER
  4. public static final int LEADING
  5. public static final int TRAILING

Constructors of FlowLayout class:

  1. FlowLayout(): creates a flow layout with centered alignment and a default 5 unit horizontal and vertical gap.
  2. FlowLayout(int align): creates a flow layout with the given alignment and a default 5 unit horizontal and vertical gap.
  3. FlowLayout(int align, int hgap, int vgap): creates a flow layout with the given alignment and the given horizontal and vertical gap.
  1. import java.awt.*;
  2. import javax.swing.*;
  3. public class MyFlowLayout{
  4. JFrame f;
  5. MyFlowLayout(){
  6.     f=new JFrame();
  7.     JButton b1=new JButton(“1”);
  8.     JButton b2=new JButton(“2”);
  9.     JButton b3=new JButton(“3”);
  10.     JButton b4=new JButton(“4”);
  11.     JButton b5=new JButton(“5”);
  12.     f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);
  13.     f.setLayout(new FlowLayout(FlowLayout.RIGHT));
  14.     //setting flow layout of right alignment
  15.     f.setSize(300,300);
  16.     f.setVisible(true);
  17. }
  18. public static void main(String[] args) {
  19.     new MyFlowLayout();
  20. }
  21. }
PinIt
submit to reddit

Leave a Reply

Top