Java:将默认Swing方向更改为RTL

时间:2014-07-01 11:33:10

标签: java swing orientation right-to-left

如何将swing的默认方向更改为RTL? 我的应用程序的所有组件都必须是RTL,我需要将默认方向更改为RTL。

我知道我们可以通过这一行改变组件方向:

Component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

但如果我这样做,我必须逐个改变所有按钮,文本字段的排列。 我的问题是如何改变挥杆的默认方向(可能是通过使用UIDefaults)。

如果我不能这样做,请说出实施此类项目的最佳方式。 (所有组件必须是RTL)


例如我们可以在这里看到改变默认FONT的解决方案: Setting the Default Font of Swing Program

我正在为ORIENTATION寻找相同的解决方案。

1 个答案:

答案 0 :(得分:1)

你可以使用它:

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;

            }
        }
    }