javacodex.com
Java Examples
Java Examples
memu home questions

FlowLayout

The FlowLayout is the simplest layout manager in Swing. It lays out the components horizontally, and then vertically. It lays the components in the order they are added to the container. When it is laying the components horizontally, it may lay them left to right, or right to left. The horizontal layout direction depends on the orientation of the container.

Source: (FlowLayoutExample.java)

import java.awt.*;
import javax.swing.*;
 
public class FlowLayoutExample {
 
  public static void main(String[] arguments) {
 
    // main window
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("FlowLayoutExample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200,200); 
 
    // set main window from to use FlowLayout
    frame.setLayout(new FlowLayout());
 
    // add a bunch of stuff to the frame
    frame.add(new JButton("Button1"));
    frame.add(new JLabel("Label1"));
    frame.add(new JButton("Button2"));
    frame.add(new JTextField("Text1"));
    frame.add(new JButton("Button3"));
    frame.add(new JLabel("Label2"));
    frame.add(new JLabel("Label2"));
 
    frame.setVisible(true);
  }
}
 

Output:

$ java FlowLayoutExample
Output



Contact: javacodex@yahoo.com