Swing does not display Unicode characters

I have some characters other than ascii that I am trying to display in a Swing JComboBox. Characters are not displayed correctly, I get a lot of weird characters where there should be non-ascii characters: Garbled ComboBox

import javax.swing.*;
public class Test {
  public static void main(String[] args) {
    String[] choices = new String[]{"Good's","Bad’s","தமிழ்"};
    for (String s : choices) System.out.println(s);
    JComboBox choiceBox = new JComboBox(choices);

    JFrame frame = new JFrame("Test");
    frame.setSize(400, 400);
    frame.add(choiceBox);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

(Note the slightly different apostrophe in Bads, and this is what started it all.)

The call System.out.printlndisplays characters that are great for my terminal.

There are a few questions about this, and they suggest listing the fonts from the GraphicsEnvironment and choosing only those that claim to display my characters. Unfortunately, this trick does not work for me.

Font font = new Font("Ariel", Font.PLAIN, 12);
for (String s : choices) assert font.canDisplayUpTo(s) < 0;
choiceBox.setFont(font);

The approval is not interrupted, but still displays distorted characters.

I'm on OSX 10.6.5, Java (TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261)

+3
3

, , ( , , , , VM, file.encoding).

, -encoding encoding= ant.

+5

, , . canDisplay - Mac. linux windows , , , Mac . Mac, Sans, Unicode. , . , , , , .

+2

JCombobox Unicode Tamil. http://www.ildc.in/Tamil/GIST/htm/otfonts.htm

Font font = new Font("TamilFont", Font.PLAIN, 12);
for (String s : choices) assert font.canDisplayUpTo(s) < 0;
choiceBox.setFont(font);
+1

All Articles