ahmed
ahmed

Reputation:

JAVA Swing GUI Components howto RTL view?

How can i make my Java Swing GUI Components [Right To Left] for Arabic language from NetBeans Desktop Application?

Upvotes: 6

Views: 6151

Answers (4)

Mina Girgis
Mina Girgis

Reputation: 40

you could use it if you have components inside panels inside contentPane

        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: 0

Markus
Markus

Reputation: 384

The call of

 Component.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT )

should do the trick. But be sure to use the SwingConstants LEADING and TRAILING instead of LEFT and RIGHT in your layouts. The same goes for GridBagConstraints.LINE_START or LINE_END instead of WEST or EAST, and probably some similar cases which I forgot to mention.

Upvotes: 5

John Gardner
John Gardner

Reputation: 25146

Don't you just have to use:

Component.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT )

I believe that the swing components all already have support for RTL, don't they?

Not sure how/where you'd do that in regards to netbeans, though.

Upvotes: 9

Uri
Uri

Reputation: 89799

You could use alignment, but that would not handle the complexities if you have English letters or numbers embedded within your text.

It might be preferable to use some sort of styled text widget or even an embedded HTML/rich text viewer.

I don't think that standard JLabels can handle the complexities otherwise.

Upvotes: 1

Related Questions