• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime localization of Swing Application  RSS feed

 
Asmita Dharap
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.
If there a simple way of achieving this without having to create an event model for all GUI pages?
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Asmita,

If you plan to provide the user an option after startup that allows them to change the language dynamically while the program is running, you could use an Event Model. Depending on the complexity of the project, you might be able to just use a JComboBox with your language choices that can call various updateLanguageText(ResourceBundle resBundle) or updateLanguageText(Locale locale) methods in your GUI related Classes.

Cheers!
Chris
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the language is changed and hence you want to change the displayed text on your GUI components you basically have two choices:
1. Have each component register themselves as a listener with a class that handles the language change and so they all get notified of the language changes and they can change their own text.
2. Have a class that keeps a reference to each displayed component and the properties file key to use to look up the text. Then when the language changes this class sets the new text on each component.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!