Internationalized Graphical User Interfaces: Component Orientation : ComponentOrientation « I18N « Java






Internationalized Graphical User Interfaces: Component Orientation

Internationalized Graphical User Interfaces: Component Orientation


import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;

public class JComboBoxDemo extends JFrame {

  public JComboBoxDemo() {
    super("JComboBoxDemo");

    String[] items = { "Anthony", "Lorraine", "Marie" };
    JComboBox itemsComboBox = new JComboBox(items);
    itemsComboBox.setEditable(true);
    itemsComboBox.setMaximumRowCount(3);
    this.getContentPane().add(itemsComboBox);
    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
    this.validate();
    this.repaint();
  }

  public static void main(String[] args) {
    JFrame frame = new JComboBoxDemo();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    frame.pack();
    frame.setVisible(true);
  }

  private void applyOrientation(Component c, ComponentOrientation o) {
    c.setComponentOrientation(o);

    if (c instanceof JMenu) {
      JMenu menu = (JMenu) c;
      int ncomponents = menu.getMenuComponentCount();
      for (int i = 0; i < ncomponents; ++i) {
        applyOrientation(menu.getMenuComponent(i), o);
      }
    } else if (c instanceof Container) {
      Container container = (Container) c;
      int ncomponents = container.getComponentCount();
      for (int i = 0; i < ncomponents; ++i) {
        applyOrientation(container.getComponent(i), o);
      }
    }
  }
}

           
       








Related examples in the same category

1.Get Component Orientation for LocaleGet Component Orientation for Locale
2.Internationalized Graphical User Interfaces: Component Orientation 1Internationalized Graphical User Interfaces: Component Orientation 1
3.Component Orientation Bundle