1.中英文混合时如何设置AWT的字体。就是说遇到英文用A字体,遇到汉字时用B字体。
2.如何设置多个字体。例如设置字体为微软雅黑,当操作系统没有此字体时使用黑体,当黑体无效时使用系统默认字体,不要显示黑框就行。
[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]
[url]http://www.java2s.com/CN/Code/Java/Swing-Components/FontChooserSourceCode.htm[/url]
嗯……被Swing的字体折磨过的飘过。
除非是排版系统,否则,还是不要指定字体吧。(Linux用户听到“微软雅黑”表示压力很大)即使是默认的字体,在有的机器上用起来也很不舒服,比如没有防锯齿,无法显示某些符号(比如汉字),字体太小,该等宽的不等宽,I、l、1不分,O、0、o不分,逗号句号不分,小尾巴“~”显示不出来……各种问题。
最好是允许用户自己设定字体吧。在某个菜单里放一个“设置字体”。