简体   繁体   中英

Change language ( localization) on-the-fly (runtime) on Java

I have read a lot of similar questions, but dont seen elegant solving for my topic.

My way to change language is restart Application as showed below:

Locale.setDefault(new Locale("de_DE"));
setVisible(false);

DlgMainApplication newApp = new DlgMainApplication();
newApp.setVisible(true);
dispose();

Is this correct way? Its works, but only inside NetBeans. When i run stand-alone .jar file, language dont change.

Thanks in advance.

A little late, but if you are using ResourceBundles with property files containing the translations, this answer here was the solution that worked for me:

https://stackoverflow.com/a/5154408/2040852

In essence: set the new locale, clear the cache of ResourceBundle and reload the bundle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM