JAVA Swing GUI组件如何实现RTL视图?

时间:2008-12-10 00:37:43

标签: java swing right-to-left

如何从NetBeans桌面应用程序中为阿拉伯语创建Java Swing GUI组件[从右到左]?

4 个答案:

答案 0 :(得分:9)

你不必只使用:

Component.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT )

我相信摆动组件都已经支持RTL了,不是吗?

不确定如何/在哪里对netbeans这样做。

答案 1 :(得分:5)

的召唤
 Component.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT )

应该做的伎俩。但请务必在布局中使用SwingConstants LEADING和TRAILING而不是LEFT和RIGHT。对于GridBagConstraints.LINE_START或LINE_END而不是WEST或EAST也是如此,可能还有一些我忘了提及的类似情况。

答案 2 :(得分:1)

您可以使用对齐方式,但如果您的文字中嵌入了英文字母或数字,则无法处理复杂问题。

最好使用某种样式化的文本小部件,甚至是嵌入式HTML /富文本查看器。

我不认为标准JLabel可以处理复杂性。

答案 3 :(得分:0)

如果在contentPane

中的面板内部有组件,则可以使用它
        Component[] component = contentPane.getComponents();
    for(int i=0; i<component.length; i++){
        component[i].applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        Component[] cp = ((Container) component[i]).getComponents();
        for(int j=0; j<cp.length; j++){
            try{
                ((Component) ((JComboBox) cp[j]).getRenderer()).applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }catch(Exception e){
                continue;

            }
        }
    }