Get the component's orientation according to the default locale and set it to the JFrame and its children - Java Swing

Java examples for Swing:FlowLayout

Introduction

This way, you do not need to set the orientation for every container in your application.

Demo Code

import java.awt.ComponentOrientation;
import java.util.Locale;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] argv) throws Exception {
    // Get the default locale
    Locale defaultLocale = JComponent.getDefaultLocale();

    // Get the component's orientation for the default locale
    ComponentOrientation componentOrientation = ComponentOrientation
        .getOrientation(defaultLocale);/*  w  ww .  ja v  a  2  s  . c  o m*/

    JFrame frame = new JFrame();
    // Apply the component's default orientation for the whole frame
    frame.applyComponentOrientation(componentOrientation);
  }
}

Related Tutorials