Swing/RegisterFont のバックアップの現在との差分(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/RegisterFont へ行く。
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:GraphicsEnvironmentにFontを登録して使用する #navi(../) #tags() RIGHT:Posted by &author(aterai); at 2009-10-19 *GraphicsEnvironmentにFontを登録して使用する [#x76fbbb3] GraphicsEnvironmentにFontを登録して、Htmlタグなどで使用できるようにします。 --- category: swing folder: RegisterFont title: GraphicsEnvironmentにFontを登録して使用する tags: [Font, GraphicsEnvironment, Html, StyleSheet, JLabel, JEditorPane, JTextPane] author: aterai pubdate: 2009-10-19T14:42:22+09:00 description: GraphicsEnvironmentにFontを登録して、Htmlタグなどで使用できるようにします。 image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTRkZgST0I/AAAAAAAAAhY/czEyIQL0NfY/s800/RegisterFont.png --- * 概要 [#summary] `GraphicsEnvironment`に`Font`を登録して、`Html`タグなどで使用できるようにします。 -&jnlp; -&jar; -&zip; #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTRkZgST0I/AAAAAAAAAhY/czEyIQL0NfY/s800/RegisterFont.png) //#screenshot #ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTRkZgST0I/AAAAAAAAAhY/czEyIQL0NfY/s800/RegisterFont.png) **サンプルコード [#r8fa1dfe] * サンプルコード [#sourcecode] #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);としておく必要があります。 * 解説 [#explanation] - `1`: `JLabel#setFont(...)`メソッドでフォントを設定して使用 - `2`: 登録したフォントを`Html`タグで指定して使用 -- `label.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)`とする必要がある -- [[JEditorPaneに設定したフォントをHTMLテキストに適用する>Swing/HonorDisplayProperties]] **参考リンク [#p3b209cd] -[http://www.creamundo.com/ creamundo | Fuentes Gratis TrueType TTF] --こちらからttfフォントを利用しています。 -[[Fontをファイルから取得>Swing/CreateFont]] -[[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]] -[[JEditorPaneのHTMLEditorKitにCSSを適用>Swing/StyleSheet]] * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/GraphicsEnvironment.html#registerFont-java.awt.Font- GraphicsEnvironment#registerFont(Font) (Java Platform SE 8)] - [http://www.creamundo.com/ creamundo | Fuentes Gratis TrueType TTF] - [[Fontをファイルから取得>Swing/CreateFont]] - [[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]] - [[JEditorPaneのHTMLEditorKitにCSSを適用>Swing/StyleSheet]] **コメント [#se35441f] * コメント [#comment] #comment #comment