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

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

Ads

Tutorials   
Java final method Assert in Java Final method in java Autoboxing in Java assert In Java JDBC batch insert using Java bean class Java Singleton Pattern Java Collection API - Java Tutorials Stack Overflow - Java Tutorials End of Year Puzzle The link to the outer class,java tutorial,java tutorials Orientating Components Right to Left,java newsletter,java,tutorial Non-virtual Methods in Java - java tutorials Multicasting in Java - java tutorials,tutorial Creation Time Comparison of Multi Dimensional Array- Java Tutorials Making Exceptions Unchecked - java tutorial,java tutorials Making Enumerations Iterable - JDK 5 Example Which is Faster - LinkedList or ArrayList? LinkedHashMap - Java Tutorials HashMap and HashCode JDK 1.4 the NullPointerException - Java Tutorials Java HashMap - Java Tutorials Java GC java awt package tutorial Java Multi Dimensions Array - Java Tutorials Java HashSet  - Java Tutorials Java Field Initialisation - Java Tutorials Java Comments - Java Tutorials J2EE Singleton Pattern - Design Pattern Tutorials Java - JDK Tutorials garbage collection in java Final Methods - Java Tutorials Exceptional Constructors - Java Tutorials Double-checked locking,java tutorials,java tutorial Disassembling Java Classes - Java Tutorials Java Deadlocks - Java Deadlocks Tutorials, Deadlocks in Java Commenting out your code - Java Tutorials Class names don't identify a class - Java Tutorials Causing Deadlocks in Swing Code Exception in Java - Java Tutorials Catching Exceptions in GUI Code - Java Tutorials boolean comparisons - tutorial Interthread Communication in Java BASIC Java - Java Tutorials Thread Deadlocks - Java Tutorials Autoboxing unboxing in Java - Java Tutorials Assertion in Java Appending Strings - Java Tutorials Anonymous Inner Classes - Anonymous Inner Classes tutorial Assertion in java
Ads

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

Ads
Share on Google+Share on Google+

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

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

Advertisements

Ads
 

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

Post your Comment


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

Ads

 

Ads