aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes change string labels of a whole application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "change string labels of a whole application" Watch "change string labels of a whole application" New topic
Author

change string labels of a whole application

alejandro garcia
Greenhorn

Joined: Aug 11, 2007
Posts: 10
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?

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
wood burning stoves
 
subject: change string labels of a whole application