【问题标题】:Setting unicode characters in java frames在java框架中设置unicode字符
【发布时间】:2010-09-25 08:09:37
【问题描述】:

如何在没有日语语言包的 Windows XP m/c 中的 java swing 中的 JFrame 标题中显示 unicode 字符(例如日语)?看起来将标题文本设置为日文 unicode 字符而将字体设置为 MS Mincho 是不够的。虽然这就是在 Swing 标签中显示 unicode 字符所需的全部操作?

【问题讨论】:

    标签: java unicode frame


    【解决方案1】:

    “没有日语语言包”?

    看来你至少要download the language font...

    字体是唯一需要安装在客户端计算机上才能运行应用程序的东西。

    与 AWT 不同,在 Swing 中使用字体要容易得多。
    对于 AWT 组件,即具有本地对等体的组件,您需要自定义 JRE 的设置,即修改 /jre/lib 下的 font.properties 以包含您在每种字体类型下安装的字体。

    在您的 Swing 应用程序中,您只需要在设置其文本之前设置 Swing 组件的字体。

    文章开头的链接包含一个完整的示例。
    小摘录:

    JFrame frame = new JFrame();
    String string = "\u30b7\u30f3\u30d7\u30eb\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf";
    JLabel label = new JLabel();
    label.setFont(new Font("MS Mincho",Font.PLAIN, 12));
    label.setText(string);
    frame.getContentPane().add(label);
    frame.setFont(new Font("MS Mincho",Font.PLAIN, 12));
    frame.setTitle(string);
    

    java J2SE6 (1.6.0) 的通用文档是here,包括Font Configuration Files

    从 Java5 及更高版本开始,您不再需要 font.properties 文件,因为您可以加载字体文件来创建/使用字体。

    String fontFileName = "yourfont.ttf";
    InputStream is = this.getClass().getResourceAsStream(fontFileName);
    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);
    Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 2013-01-31
      • 2012-12-02
      • 1970-01-01
      相关资源
      最近更新 更多