Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

change string labels of a whole application  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! here I've got a Selector class which shows a combo box and a label, in the combo box the user can select the language in which he wants the label to be showed, getting the translation from the Datos.PROPERTIES file.
That works fine.

Now I need to extend it so that this selection class selects the language of all the menues of an application.

The question is: do I have to add all the labels of the application in the if-then-else sentence of the selection class?
I mean that in the selection class I show here there's an if then else sentence depending on the language selected, do I have to put all the labels of all the menues of the application in there?

 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by alejandro garcia:

The question is: do I have to add all the labels of the application in the if-then-else sentence of the selection class?



1) Extend JLabel and call it say RBLabel
2) Whenever you create a new instanceof RBLabel add it as an action listener to the JComboBox so that whenever the user changes the value in the JComboBox, all the instances of RBLabel get notified.
3) In actionPerformed() of RBLabel write the code which will get the selected language, load the correct resource bundle and get the translated text. Once you get the translated text, you can always call this.setText(translatedText)

To make it more elegant you can consider a utility class which will do the job of loading the resource bundle. In that case you will need a method in the utility class which will provide you the translated text.

Does this make sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!