I have several GUI forms in my java application. All of forms have texts. I had set texts to my components from a shared object called dictionary. I need a feature in my program; to switch language as user wants; such that all texts in all forms be replaced with another language. I have all texts in a shared Dictionary object. is there any clean way to change language in a clean way?
I know about netbeans Internationalization tool but I want to use another method.
Edit: for example:
label1.setText(Dictionary.Hello);
and Dictionary class is defined as:
public class Dictionary {
public static String Hello = "hello";
}
and for another language:
public class DictionaryPersian extends Dictionary {
public DictionaryPersian(){
Hello = "درود";
}
}
I want to find a way way to bind the field Dictionary.hello to jlabel1 such that as this variable value changed it be reflected on jlabel1 text.
You could subclass JLabel for instance, setting text directly from the dictionary using some id. It can also act as listener to text or language changes to automatically change displayed text accordingly.
For explanation sake some code snipped (not tested, nor complete, the dictionary label can be implemented differently if you like, also your dictionaries should implement
IDictionary)As I said, just some example snipped I hope you get the idea.