So you can do this by using a language file. It would be something like:
1 - Method to retrieve the selected language file based on the selected language option in JMenuItem (.lang files would be in the project lang folder):
class Language {
private Properties language;
public void loadLanguage(int lang) throws FileNotFoundException,
IOException {
if (lang == 0)
language = getLanguageProperties("lang/english.lang");
else if (lang == 1)
language = getLanguageProperties("lang/portuguese.lang");
}
protected Properties getLanguageProperties(String languageFile)
throws FileNotFoundException, IOException {
File file = new File(languageFile);
Properties props = new Properties();
props.load(new FileInputStream(file));
return props;
}
}
2- Retrieve the text of a component through your key:
class LanguageController {
public static String getProperty(String key) {
return language.getProperty(key);
}
}
3- Load text from application swing components:
JButton componente = new JButton();
componente.setText(
LanguageController.getProperty(
"BOTAO_KEY")
4- The language file would contain the content with the key and value ("portuguese.lang"):
BOTAO_KEY=Texto do meu button
If you're curious, take a look at the project where I did this internationalization treatment: link . There is a language menu that allows the user to change the language at runtime. I hope I have helped ^^