本文整理汇总了Java中java.awt.GraphicsEnvironment.preferLocaleFonts方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsEnvironment.preferLocaleFonts方法的具体用法?Java GraphicsEnvironment.preferLocaleFonts怎么用?Java GraphicsEnvironment.preferLocaleFonts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.GraphicsEnvironment
的用法示例。
在下文中一共展示了GraphicsEnvironment.preferLocaleFonts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println("Default Charset = "
+ Charset.defaultCharset().name());
System.out.println("Locale = " + Locale.getDefault());
String os = System.getProperty("os.name");
String encoding = System.getProperty("file.encoding");
/* Want to test the JA locale uses alternate font for DialogInput. */
boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
if (!os.startsWith("Win") && jaTest) {
System.out.println("Skipping Windows only test");
return;
}
String className = "sun.java2d.SunGraphicsEnvironment";
String methodName = "useAlternateFontforJALocales";
Class sge = Class.forName(className);
Method uafMethod = sge.getMethod(methodName, (Class[])null);
Object ret = uafMethod.invoke(null);
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.preferLocaleFonts();
ge.preferProportionalFonts();
if (jaTest) {
Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
System.out.println("MS Mincho not installed. Skipping test");
return;
}
Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
Font courierNew = new Font("Courier New", Font.PLAIN, 12);
Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
BufferedImage bi = new BufferedImage(1,1,1);
Graphics2D g2d = bi.createGraphics();
FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
// This tests to make sure we at least have applied
// "preferLocaleFonts for Japanese
if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
throw new RuntimeException
("Courier New should not be used for DialogInput");
}
// This is supposed to make sure we are using MS Mincho instead
// of MS Gothic. However they are metrics identical so its
// not definite proof.
if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
throw new RuntimeException
("MS Mincho should be used for DialogInput");
}
}
}