繁体   English   中英

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

[英]Java: Change Default Swing Orientation To RTL

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

我知道我们可以通过以下行更改组件方向:

Component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

但是,如果执行此操作,则必须一一更改所有按钮,文本字段的方向。 我的问题是如何更改默认的挥杆方向(也许通过使用UIDefaults)。

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


例如,我们可以在此处查看更改默认FONT的解决方案: 设置Swing程序的默认字体

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

您可以使用它:

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;

            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM