To create a Font object to draw text, it is necessary to specify the font face name. This example demonstrates how to retrieve all the font face names from a font family name. Unfortunately, the method is somewhat inefficient since it involves creating one-point size Font objects for every available font in the system. The example caches all the information by 建立一个散列表 that maps a font family name to an array of font face names.

See also e651 列出所有可用字体. Note: J2SE 1.4 only support True Type fonts.

    Map fontFaceNames = new HashMap();

    // Get all available font faces names
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts(); // Process each font
for (int i=0; i<fonts.length; i++) {
// Get font's family and face
String familyName = fonts[i].getFamily();
String faceName = fonts[i].getName(); // Add font to table
java.util.List list = (java.util.List)fontFaceNames.get(familyName);
if (list == null) {
list = new ArrayList();
fontFaceNames.put(familyName, list); }
list.add(faceName);
} // Replace the face name lists with string arrays,
// which are more compact and convenient to use
for (Iterator it=fontFaceNames.keySet().iterator(); it.hasNext(); ) {
String familyName = (String)it.next();
java.util.List list = (java.util.List)fontFaceNames.get(familyName);
fontFaceNames.put(familyName, list.toArray(new String[list.size()]));
} // Use the table
String[] faces = (String[])fontFaceNames.get("Verdana");
Related Examples

e652. Getting the Font Faces for a Font Family的更多相关文章

  1. [函数] Firemonkey Windows 重新计算 Font Baseline

    计算字型 Baseline 是一个不常用的函数,但如果想要显示不同大小文字下方对齐,就得用它来计算字型的 Baseline 才行,如果计算不准,显示的文字就会高高低低不整齐. 在 Firemonkey ...

  2. java 引入自定义字体font后出现的硬盘吃光的问题

    有个需求要用美术字体在图片上写字 用自定义的文字有两个方法: 1. Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, InputStream ...

  3. Android 使用Font Awesome 显示文字图标

    Android 使用Font Awesome 显示文字图标 简单几步就可以完成 简单的效果图: 1. 创建 assets 文件夹 在Android Studio 上的创建步骤为: 在 src/main ...

  4. Label Font 字体样式设置

    label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: Font Family: Amer ...

  5. Java基础之扩展GUI——使用字体对话框(Sketcher 5 displaying a font dialog)

    控制台程序. 为了可以选择系统支持的字体,我们定义了一个FontDialog类: // Class to define a dialog to choose a font import java.aw ...

  6. iOS FONT字体名

    下面这段代码可以查看ios中可用的字体,具体那些字体长什么样,可以查看字体册工具. NSArray *familyArray = [UIFont familyNames]; for (id famil ...

  7. css基础之 font的简写规则 以及 自定义 CSS3 @font-face详细用法

    Part 1 font简写 CSS的命名规则是用英文字母 数字 和下划线(一般用小写)来命名.简写css font的好处有三:一是写起来方便(就像键盘快捷键):二是简化代码:三是帮助你熟悉和深刻理解c ...

  8. css font简写规则

    是不是在很很多网站的公共样式中会看到这样的代码?font: 12px/150% Arial, Verdana, "\5b8b\4f53";意思为:字体大小/行高 字体族 " ...

  9. 【CSS】font样式简写(转)- 不是很建议简写

    一.字体属性主要包括下面几个 font-family,font-style,font-variant,font-weight,font-size,font font-family(字体族): “Ari ...

随机推荐

  1. ubuntu 16.04 apt-get 更新使用中科大镜像源

    1 备份系统配置 sudo cp /etc/apt/sources.list /etc/apt/source.list.bak 2 编辑配置 sudo vi /etc/apt/sources.list ...

  2. ev3dev:c语言开发lego ev3主机

    有了ev3dev,真是一且皆有可能啊,最近,看到一个好人,居然做了一个ev3的c库. 激动中... 学习有目标了...,赶紧记录一下. https://github.com/theZiz/ev3c

  3. iptables的地址取反操作

    感叹号要写在-d的前面才行,而且要用空格隔开. iptables -A OUTPUT -o eth0 -p tcp ! -d xxx.xxx.xxx.xxx -j DROP

  4. 简易C#动态加载dll(实现插件化)

    可以通过该方法来实现程序插件化. 假设A,B两个类,A类为宿主,B类为插件需要加载到A类中: class Program { public interface IHellow { void Hello ...

  5. quartusii 使用ModelSim do文件实现仿真(Verilog)

    QuartusII从9.1之后的版本都已经取消了内部自带的仿真器,都需要借助第三方仿真软件比如Modelsim才能实现仿真.一般在进行代码编写的时候,如果结合功能仿真,可以很快的验证代码实现的逻辑是否 ...

  6. node.js 使用ejs模板引擎时后缀换成.html

    这是一个小技巧,看着.ejs的后缀总觉得不爽,使用如下方法,可以将模板文件的后缀换成我们习惯的.html. 1.在app.js的头上定义ejs: 代码如下: var ejs = require('ej ...

  7. JNI-获取Java对象的成员变量-GeInttField()

    例: 在Java中定义一个属性,然后用C语言将其设置成另外的值,并输出出来. Java代码: Person.java package com.yuneec.demo; public class Per ...

  8. Windows mobile 下读取手机SIM卡信息(转)

    Windows mobile 下读取手机SIM卡信息 c#改善 Windows mobile 下读取手机SIM卡信息

  9. ny236 心急的C小加 hdoj1051 Wooden Sticks

    心急的C小加 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间 ...

  10. Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]

    declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowTyp ...