theAnonymous
theAnonymous

Reputation: 1804

multi language in Component

I am using Swing, and I need the components to be able to display multiple languages at the same time (inside one component). However, the characters other than English characters are displayed as squares.

The Components are just JTextPane, JEditorPane, JTextField, JTextArea and all the default stuff.

What must I do to achieve the goal of multi language support?

Upvotes: 1

Views: 287

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109547

Use a full Unicode font. They are large. Then setFont(...) does the trick.

If you want to pack a font with your application loadFont and registerFont will do.

    Font font = Font.createFont(Font.TRUETYPE_FONT,
        getClass().getResourceAsStream("/..."));
    GraphicsEnvironment ge =
        GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.registerFont(font);

Upvotes: 1

trashgod
trashgod

Reputation: 205775

On most platforms, the default logical font family specified by each component's UI delegate has the required glyphs for supported locales. If you override these defaults with a particular physical font using setFont(), you may be able to get the desired result using deriveFont(), as suggested in theses examples. If you must use a particular physical font, you'll have to verify that the required glyphs are present. FontShower may be a useful adjunct.

Upvotes: 1

Related Questions