multi language in Component

假如想象 提交于 2019-12-24 10:41:00

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/24733375/multi-language-in-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!