views:

232

answers:

3

Can the swing application framework be used to implement multilanguage swing applications? If so, how should it be done? Should I use multiple .properties files, one for each language? How can I let the system know which properties file to use then? Does anybody know a good tutorial for this?

A: 

Short answer: yes it can, and yes you should.

Here's a short bit of user-friendly blurb on it: http://chaoticjava.com/posts/the-quiet-revolution-part-i-jsr-296/

However, a word of warning: According to the web-site for the JSR http://jcp.org/en/jsr/detail?id=296 It is currently inactive.

William Billingsley
+1  A: 

take a look to the ResourceBundle class and this tutorial.

NB: this class is not tied to Swing, you can use it in console or web applications)

dfa
+2  A: 

You can put the following in your base panel class (or anywhere else, and plug it in):

public ResourceMap getResourceMap() {
    if (resourceMap == null) {
        ApplicationContext context = getContext();
        if (context != null) {
            resourceMap = context.getResourceMap(getResourceStartClass(), 
                   getResourceStopClass());
        }
    }

    return resourceMap;
}

public ApplicationContext getContext() {
    if (applicationContext == null) {
        Application app = getApplication();
        if (app != null) {
            applicationContext = app.getContext();
        }
    }

    return applicationContext;
}

public Application getApplication() {
    if (application == null) {
        application = Application.getInstance();
    }

    return application;
}
Bozho
Thanks for this. This works for me, together with having the correct name for the properties files...Although it looks a bit weird you apply the singleton pattern in your getApplication() method. This looks like overhead to me. Why don't you just call 'Application.getInstance()' here?
Fortega
it's some kind of lazy loading. I got this from an old codebase, so if Application.getInstance() is itself lazy, you can omit that method.
Bozho