TITLE:GraphicsEnvironmentにFontを登録して使用する
#navi(../)
#tags()
RIGHT:Posted by &author(aterai); at 2009-10-19
*GraphicsEnvironmentにFontを登録して使用する [#x76fbbb3]
GraphicsEnvironmentにFontを登録して、Htmlタグなどで使用できるようにします。

-&jnlp;
-&jar;
-&zip;

//#screenshot
#ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTRkZgST0I/AAAAAAAAAhY/czEyIQL0NfY/s800/RegisterFont.png)

**サンプルコード [#r8fa1dfe]
#code(link){{
Font font = makeFont(getClass().getResource("Burnstown Dam.ttf"));
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
}}

**解説 [#v79aaeaf]
-1. JLabel#setFont メソッドでフォントを設定しています。
-2. 登録したフォントをHtmlタグで指定して使用しています。
-- lable.setText("<html><font size='+3' face='Burnstown Dam'>2: html,font,size,+3</font></html>");
-3. StyleSheetでbodyタグのフォントを設定しています。
-- styleSheet.addRule("body {font-size: 24pt; font-family: Burnstown Dam;}");
-4. JTextPane#setFont メソッドでフォントを設定しています。
-- bodyタグで指定されているフォントを無視して、JTextPaneのデフォルトのフォントを使用したい場合は、editor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);としておく必要があります。

**参考リンク [#p3b209cd]
-[http://www.creamundo.com/ creamundo | Fuentes Gratis TrueType TTF]
--こちらからttfフォントを利用しています。
-[[Fontをファイルから取得>Swing/CreateFont]]
-[[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]]
-[[JEditorPaneのHTMLEditorKitにCSSを適用>Swing/StyleSheet]]

**コメント [#se35441f]
#comment