Fadavi
Fadavi

Reputation: 48

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.

Upvotes: 1

Views: 871

Answers (1)

Mina Girgis
Mina Girgis

Reputation: 40

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;

            }
        }
    }

Upvotes: 2

Related Questions