chunquedong 2011-08-08 18:14
浏览 757
已采纳

Java字体设置问题

1.中英文混合时如何设置AWT的字体。就是说遇到英文用A字体,遇到汉字时用B字体。
2.如何设置多个字体。例如设置字体为微软雅黑,当操作系统没有此字体时使用黑体,当黑体无效时使用系统默认字体,不要显示黑框就行。

  • 写回答

3条回答 默认 最新

  • suziwen 2011-08-08 21:42
    关注

    [code="java"]String[] fontNames = GraphicsEnvironment
    .getLocalGraphicsEnvironment()
    .getAvailableFontFamilyNames();

        //... Make vector of all fonts that can display basic chars.
        //    Vector (not newer ArrayList) is used by JComboBox.
        Vector<String> visFonts = new Vector<String>(fontNames.length);
        for (String fontName : fontNames) {
            Font f = new Font(fontName, Font.PLAIN, 12);
            if (f.canDisplay('a')) {
                //... Display only fonts that have the alphabetic characters.
                visFonts.add(fontName);
            } else {
                //    On my machine there are almost 20 fonts (eg, Wingdings)
                //    that don't display text.
                //System.out.println("No alphabetics in " + fontName);
            }
        }
        [/code]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?