gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:50:45 26 4
gpt4 key购买 nike

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

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

Component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

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

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

<小时/>

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

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

最佳答案

你可以使用它:

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;

}
}
}

关于Java:将默认 Swing 方向更改为 RTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24509252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com