【问题标题】:Java: Change Default Swing Orientation To RTLJava:将默认摆动方向更改为 RTL
【发布时间】:2014-07-01 11:33:09
【问题描述】:

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

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

Component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

但如果我这样做,我必须一一改变所有按钮、文本字段等的方向。 我的问题只是如何改变摇摆的默认方向(也许通过使用 UIDefaults)。

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


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

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

【问题讨论】:

    标签: java swing orientation right-to-left


    【解决方案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;
    
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-12
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多