4

私は英語、ロシア語、韓国語をサポートするJavaアプリケーションに取り組んでいます。

そこで、言語ごとにユニコードでプロパティファイルを用意しました。次に、バンドルから_関数を使用して文字列値を取得し、次のように設定します。

  • 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);
}

英語とロシア語の場合、それは完璧に機能します。韓国語の場合、JTextAreaは韓国語の文字を正しく表示しますが、JLabelは表示しません。正方形が表示され、Eclipseコンソールでは??と表示されますが、ロシアの文字はEclipseコンソールで正しく表示できます。

したがって、JLabelに問題があるようです。

4

1 に答える 1

4

@mKorbelが簡単に識別したように、問題はJLabelフォントにありました。

アプリケーションの起動時に、Locale.getDefault()から言語を特定するか、ユーザーに選択を依頼します。次に、選択した言語に従って.propertiesファイルを選択するためのパスを生成します。

韓国語のファイルに入れました(Eclipse AnyEditプラグインを使用しています)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);
于 2012-10-16T10:57:21.773 に答える