5

I am working on Java application which should support English, Russia and Korean languages.

So I have prepared properties files in unicode for each languages. Then I get some String value using _ function from bundle to set it to

  • JLabel
  • JTextArea


InputStream stream = LocaleManager.class.getClassLoader().getResourceAsStream(path);
ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));

public static String _(String key) {
    return bundle.getString(key);
}

For English and Russian it works perfect. For Korean JTextArea shows Korean charecters correctly but JLabel does not. It shows squares and in Eclipse console it shows ??, however Russia characters can be shown correctly in Eclipse console.

So seems like problem with JLabel.

Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
  • 3
    can you please to demonstrated your issue, post an [SSCCE](http://sscce.org/), and please to use Unicode ("\uxxxx") instead of pasted text (internet explorer issue, could be used various Encoding Page settings), there are two ways, wrong Charset for Encode from property file (especially on Windows platform) or Font that doesn't supports Korean Glyphs, example for your [SSCCE](http://stackoverflow.com/a/12903751/714968) – mKorbel Oct 16 '12 at 10:32
  • @mKorbel, you are right the problem was with the font. I was setting Verdana for the jLabel. I have commented that line and now Korean characters are shown okay. – Nikolay Kuznetsov Oct 16 '12 at 10:36
  • You can post the answer and I would accept it. Thanks – Nikolay Kuznetsov Oct 16 '12 at 10:36
  • 1
    +1 no thanks, but for future readers coud be interesting reading, please you can to too, post by yourself, accept that (past 24hours), but please with an SSCCE, then you'll get my upvote to your answer :-).... – mKorbel Oct 16 '12 at 10:40
  • @mKorbel done, I have tried my best to explain. – Nikolay Kuznetsov Oct 16 '12 at 10:59

1 Answers1

4

As @mKorbel easily identified the problem was with JLabel font.

On application startup identify the language from Locale.getDefault() or ask the user to select. Then generate the path to pick .properties file according to the language selected.

In the file for Korean language I put (I use Eclipse AnyEdit plugin) Swimming=\u0412\u043e\u0434\u043d\u043e\u0435 Running=\u0411\u044b\u0441\u0442\u0440\u043e\u0435

InputStream stream = LocaleManager.class.getClassLoader().getResourceAsStream(path);
ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));

//get internationalized version for "Swimming"
String str = _("Swimming");

//create and configure JLabel
JLabel label = new JLabel();
label.setVisible(true);
label.setBackground(Color.yellow);
label.setOpaque(true);

//this line was the issue
label.setFont(new Font("Verdana", Font.PLAIN, 14));

//setting text which results in squares
label.setText(str);
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101