Online-Academy

Look, Read, Understand, Apply

Menu

FlowLayout

FlowLayout

FlowLayout is default layout for JPanel; components are arranged in left to right, top to bottom in the container.

setLayout(new FlowLayout()); method is called to set layout of container to FlowLayout

import java.awt.*;

import javax.swing.*;
class abcFlow extends JFrame{
    JLabel name;
    JButton btn1,btn2,btn3;
    JTextField tname;
    public abcFlow(){
        
        name = new JLabel("Enter Name");
        tname = new JTextField(20);
        btn1 = new JButton("East");
        btn2 = new JButton("West");
        btn3 = new JButton("Center");
        //Layout manager: specifies how the components are arranged on the container
        //by default layout of JFrame is BorderLayout
        //BorderLayout divides container into five parts: east,west,south,north,center
        add(name);
        add(tname);
        add(btn1);
        add(btn2);
        add(btn3);
        setLayout(new FlowLayout());//changing default layout to Flowlayout
        setSize(400,300);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public static void main(String[] args){
     abcFlow a = new abcFlow();  
    }
}