简体   繁体   中英

Java: Change Default Swing Orientation To RTL

How can I change default orientation of swing to RTL? All components of my application must be RTL and I need to change default orientation to RTL.

I know we can change Component orientation by this line:

Component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

But if I do this, I must change orietation of all buttons, textfields, ... one by one. My question just is how change default orientation of swing (maybe by use of UIDefaults).

If I can't do this, please say best way to implement such project. (All of components must be RTL)


for example we can see solution of changing default FONT in swing here: Setting the Default Font of Swing Program

Im looking for same solution for ORIENTATION.

you could use it:

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;

            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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