java dev
java dev

Reputation: 372

Switch system language in java programming

Is there a way to switch the system language in java programming? I do a java dictionary application so I use two Jtextfield one for English and the other for Arabic I want when focusing on the English Jtextfield switch system language to English and similar in Arabic Jtextfield.

Upvotes: 0

Views: 193

Answers (1)

Wojtek
Wojtek

Reputation: 1308

Try using this methods:

public void setArabic(JTextField txt) {
    txt.getInputContext().selectInputMethod(new Locale("ar", "SA"));
    txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);    
}

public void setEnglish(JTextField txt) {
    txt.getInputContext().selectInputMethod(new Locale("en", "US"));
    txt.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);    
}

Upvotes: 4

Related Questions