Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / June 2005

Tip: Looking for answers? Try searching our database.

I18n of combo-box in PropertyEditor

Thread view: 
Nemo - 30 May 2005 00:47 GMT
I have a drop-down box (Combo) which is used to select between several
different strings. For example (not the real one!):

Translate text into : English
                             French
                             Italian
                             Esperanto
                             ....

Depending on which language is chosen, the Property will be set to the
string "English" or "French" etc.

All well and good, until one translates the text into other languages.

AFAICS one has to compare the response against the current list of
translations to find out which has been chosen. This is messy and seems
unnecessary.

Is it possible to define the property tag list as the fixed resource
keys (e.g. key_en, key_fr, key_it) and somehow translate to/from the
locale-specific text in the GUI?

So the property would only ever know about resource keys, but the
property editor would be able to work with the corresponding resource
values.

Seems to me this must be a common i18n problem, but I've been unable to
find anything in my searches.
Christian Schlichtherle - 14 Jun 2005 17:12 GMT
Hi,

one way to deal with this is to initialize the JComboBox with an array of
objects. The combobox will then display the return values of the toString()
method. This is where your internationalized string should go. If you change
the return values of your combo box later, you'll need to call repaint() on
the combo box in order to ensure the combo box recognizes the changes.

If you call getSelectedItem() on the combo box, you will always get the
array element as a reference, so you can use this to identify the user's
choice.

That's simple and worked fine for me.

However, if you have a combo box with hundreds or thousands of elements, you
should probably not call repaint() all the times. Consider implementing a
JComboBoxModel instead and notify the combo box by firing the corresponding
event (the combo box is a listener of the model) instead.

There is also a chapter on this in the online Swing tutorial at Sun's web
site, but I can't exactly recollect which chapter. Try the one on JComboBox.

Regards,
Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.