Component: setComponentOrientation(ComponentOrientation o) : Component « java.awt « Java by API






Component: setComponentOrientation(ComponentOrientation o)

  


import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;

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

public class Main extends JFrame {

  public Main() {
    JComboBox itemsComboBox = new JComboBox(new String[]{ "A", "L", "M" });
    itemsComboBox.setEditable(true);
    itemsComboBox.setMaximumRowCount(3);
    this.getContentPane().add(itemsComboBox);
    itemsComboBox.setVisible(true);
    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
    this.validate();
    this.repaint();
  }

  public static void main(String[] args) {
    JFrame frame = new Main();
    frame.setDefaultCloseOperation(JFrame.EXIT_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.Component.BOTTOM_ALIGNMENT
2.Component.CENTER_ALIGNMENT
3.Component.LEFT_ALIGNMENT
4.Component.RIGHT_ALIGNMENT
5.Component.TOP_ALIGNMENT
6.Component: enableEvents(long eventsToEnable)
7.Component: getAccessibleContext()
8.Component: getLocationOnScreen()
9.Component: isFocusable()
10.Component: isFocusCycleRoot
11.Component: requestFocusInWindow()
12.Component: setBounds(int x,int y,int width,int height)
13.Component: setLocation(int x, int y)
14.Component: setSize(int width, int height)