Home Javatutorials Orientating Components Right to Left,java newsletter,java,tutorial
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

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

Advertisement
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-

SampleInterfaceImp.java

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);
		applyComponentOrientation(componentOrientation);
	}

	private static void viewWindow(ComponentOrientation cOrientation) {
		ComponentArrangementExample componentOrientation = new ComponentArrangementExample(
				cOrientation);
		componentOrientation.setSize(500, 350);
		componentOrientation.setAlwaysOnTop(true);
		componentOrientation.setLocationByPlatform(true);
		componentOrientation.setDefaultCloseOperation(EXIT_ON_CLOSE);
		componentOrientation.setTitle("Component Arrangement Example");
		componentOrientation.setVisible(true);
	}

	private JLabel assignLevel(String str) {
		JLabel label = new JLabel(str);
		label.setBorder(BorderFactory.createRaisedBevelBorder());
		return label;
	}

	public static void main(String[] args) {
		viewWindow(ComponentOrientation.RIGHT_TO_LEFT);
	}
}

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


 
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: Orientating Components Right to Left,java newsletter,java,tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com