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 / GUI / June 2005

Tip: Looking for answers? Try searching our database.

I18n of combo-box in PropertyEditor

Thread view: 
Nemo - 08 Jun 2005 22:56 GMT
[Tried posting in clj.beans, but that seems to be rather quiet and I now
realise that the query is more GUI oriented anyway. Apologies if you
have seen it before.]

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.
Signature

Nemo (nemo@stian.demon.co.uk)

Thomas Weidenfeller - 09 Jun 2005 08:04 GMT
> 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?

The simplest would be to use getSelectedIndex() and just work with the
index.

The second simplest would be to use the index to build a key:

    String key = "SomeFixedPart_" + aComboBox.getSelectedIndex();

If your really need symbolic names, use the fact that the JComboBox
takes any kind of Object for items:

    public class ComboBoxItem {
        String label;
        String key;

        public void ComboBoxItem(String l, String k) {
            label = l;
            key   = k;
        }

        public String toString() {
            return label;
        }

        public String getKey() {
            return key;
        }
       
    }

    ((ComboBoxItem)aComboBox.getSelectedItem()).getKey();

But this is almost overdone.

> Seems to me this must be a common i18n problem, but I've been unable to
> find anything in my searches.

There is no such problem. You are making things more complicated then
they are.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Nemo - 11 Jun 2005 15:07 GMT
>> 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?
>
>The simplest would be to use getSelectedIndex() and just work with the
>index.

[...]

>But this is almost overdone.
>
[quoted text clipped - 3 lines]
>There is no such problem. You are making things more complicated then
>they are.

Thanks, agreed, as stated the problem was not difficult - the index
would do fine.

My fault, I failed to provide the full context.
The environment is a Bean Customiser that provides the Combo box.
The values are set from the list of Tags.
I've tried updating setAsText() and getAsText() in the PropertyEditor
but keep getting errors from the customiser saying that the selected
value was incorrect.

However on further investigation it looks as though the Customiser
and/or PropertyEditor may need updating.

On a related note, I failed to find any examples of Bean Property
Editors that support the behaviour. Nor indeed any that support Enums.
Obviously one can do both of these with radio buttons, but they are not
suitable where there are lots of possible different values.
Signature

Nemo (nemo@stian.demon.co.uk)



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.