Share on Google+Share on Google+

Orientating Components Right to Left,java newsletter,java,tutorial

This page discusses - Orientating Components Right to Left,java newsletter,java,tutorial

Arranging Components

We often arrange the components either from left to write or right to left. For the components orientation we uses Layout Manager. There are many type of Layout manager they are

BorderLayout, BoxLayout, CardLayout, FlowLayout, GridLayout, GridBagLayout, GroupLayout and SpringLayout. Each of these Layout Managers arranges the components in some there specific way, like BorderLayout arranges the components in file areas they are top, bottom, right, left and center. The BoxLayout arranges the components either in single row or column.

You can also use the ComponentOrientation class to arrange the components. It encapsulates the language sensitive orientation that can be used to order the text or components. The ComponentOrientation class is used to reflect the differences in ordering between alphabets such as Western alphabets, Middle Eastern or Far Eastern.

Consider an example given below-

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ComponentArrangementExample extends JFrame {
	public ComponentArrangementExample(ComponentOrientation componentOrientation) {
		super(componentOrientation.isLeftToRight() ? "Left" : "Right");
		add(assignLevel("PageStart"), BorderLayout.PAGE_START);
		add(assignLevel("LineStart"), BorderLayout.LINE_START);
		add(assignLevel("LineEnd"), BorderLayout.LINE_END);
		add(assignLevel("PageEnd"), BorderLayout.PAGE_END);
		add(assignLevel("PageCentre"), BorderLayout.CENTER);

	private static void viewWindow(ComponentOrientation cOrientation) {
		ComponentArrangementExample componentOrientation = new ComponentArrangementExample(
		componentOrientation.setSize(500, 350);
		componentOrientation.setTitle("Component Arrangement Example");

	private JLabel assignLevel(String str) {
		JLabel label = new JLabel(str);
		return label;

	public static void main(String[] args) {

When you will run this program you will the output as below



Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Orientating Components Right to Left,java newsletter,java,tutorial  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image