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. 如何发布Node模块到NPM社区

    “学骑自行车最快的方式就是先骑上去” 一.安装node和npm 1.一种是通过编译node源文件安装node(注意:需要Python 2.6或2.7已经安装) $ wget http://nodejs ...

  2. 在为shader program pass uniform之前一定要先use program。

    在为shader program pass uniform之前一定要先use program.

  3. Spring RestTemplate使用教程

    简介 Spring'scentral class for synchronous client-side HTTP access.It simplifies communication with HT ...

  4. Oracle删除重复记录只保留一条数据的几种方法

    1. 问题描述 BBSCOMMENT表为BBSDETAIL的从表,记录商户评价信息.因为数据倒腾来倒腾去的,有很多重复数据.表结构如下: COMMENT_ID NOT NULL NUMBER --主键 ...

  5. NGUI ScrollView出屏幕再回来坐标混乱解决

    主要是子节点没更新.乍一看调用UIPanel的Refresh()会管用,其实不然. 解决方法调用UIPanel的Invalidate让他所有子节点更新. panel.Invalidate(true);

  6. SDUT 1941-Friday the Thirteenth(水)

    Friday the Thirteenth Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述  Is Friday the 13 ...

  7. 基于epoll的简单的httpserver

    该httpserver已经能够处理并发连接,支持多个client并发訪问,每一个连接能够持续读写数据.当然.这仅仅是一个简单的学习样例.还有非常多bug,发表出来仅仅是希望大家能够互相学习.我也在不断 ...

  8. static_cast、dynamic_cast、reinterpret_cast、和const_cast

    关于强制类型转换的问题,很多书都讨论过,写的最详细的是C++ 之父的<C++ 的设计和演化>.最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_ ...

  9. Python 2.7.9 Demo - 003.01.只允许相同缩进

    Right #!/usr/bin/python if True: print ("True"); print('Again'); else: print ("False& ...

  10. python常用的十进制、16进制、字符串、字节串之间的转换

    进行协议解析时,总是会遇到各种各样的数据转换的问题,从二进制到十进制,从字节串到整数等等 废话不多上,直接上例子 整数之间的进制转换: 10进制转16进制: hex(16)  ==>  0x10 ...