What is FlowLayout - Java Swing

Java examples for Swing:FlowLayout

Introduction

FlowLayout lays out the components horizontally, and then vertically.

FlowLayout lays out the components in the order they are added to the container.

When FlowLayout is laying out the components horizontally, it may lay them left to right, or right to left.

The horizontal layout of FlowLayout direction depends on the orientation of the container.

To set the orientation of a container by calling its setComponentOrientation() method.

To set the orientation of a container and all its children, use the applyComponentOrientation() method.

The following code sets the orientation of the content pane of a frame to "right to left".

Demo Code

import java.awt.ComponentOrientation;
import java.awt.Container;

import javax.swing.JFrame;

public class Main {
  public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame("Test");
    Container pane = frame.getContentPane();
    pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  }/*w w  w .  j  ava 2  s . c om*/
}

The following code sets the orientation of the content pane and all its children to "right to left".

Demo Code

import java.awt.ComponentOrientation;
import java.awt.Container;

import javax.swing.JFrame;

public class Main {
  public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame("Test");
    Container pane = frame.getContentPane();
    pane.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  }//from  w w w  .  j  a va  2  s .c om
}

Related Tutorials