Java by API/java.awt/ComponentOrientation
Содержание
ComponentOrientation: getOrientation(Locale locale)
<source lang="java">
import java.awt.ruponentOrientation; import java.util.Locale; public class Main {
public static void main(String[] argv) throws Exception { Locale myLocale = Locale.getDefault(); ComponentOrientation ce = ComponentOrientation.getOrientation(myLocale); System.out.println("Is horizontal? " + ce.isHorizontal()); System.out.println("Is left to right? " + ce.isLeftToRight()); }
}
</source>
ComponentOrientation: isHorizontal()
<source lang="java">
import java.awt.ruponentOrientation; import java.util.Locale; public class Main {
public static void main(String[] argv) throws Exception { Locale myLocale; if (argv.length < 2) myLocale = Locale.getDefault(); else myLocale = new Locale(argv[0], argv[1]); ComponentOrientation ce = ComponentOrientation.getOrientation(myLocale); System.out.println("Is horizontal? " + ce.isHorizontal()); System.out.println("Is left to right? " + ce.isLeftToRight()); }
}
</source>
ComponentOrientation: isLeftToRight()
<source lang="java">
import java.awt.ruponentOrientation; import java.util.Locale; public class Main {
public static void main(String[] argv) throws Exception { Locale myLocale; if (argv.length < 2) myLocale = Locale.getDefault(); else myLocale = new Locale(argv[0], argv[1]); ComponentOrientation ce = ComponentOrientation.getOrientation(myLocale); System.out.println("Is horizontal? " + ce.isHorizontal()); System.out.println("Is left to right? " + ce.isLeftToRight()); }
}
</source>
ComponentOrientation.RIGHT_TO_LEFT
<source lang="java">
import java.awt.ruponent; import java.awt.ruponentOrientation; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; public class MainClass extends JFrame {
public MainClass() { super("MainClass"); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(new JButton("OK")); contentPane.add(new JButton("Cancel")); applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT); } public static void main(String[] argv) { JFrame frame = new MainClass(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); 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); } } }
}
</source>