GraphicsEnvironmentにFontを登録して使用する
Total: 8001, Today: 1, Yesterday: 7
Posted by aterai at
Last-modified:
Summary
GraphicsEnvironmentにFontを登録して、Htmlタグなどで使用できるようにします。
Screenshot

Advertisement
Source Code Examples
Font font = makeFont(getClass().getResource("Burnstown Dam.ttf"));
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
View in GitHub: Java, KotlinDescription
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テキストに適用する
Reference
- GraphicsEnvironment#registerFont(Font) (Java Platform SE 8)
- creamundo | Fuentes Gratis TrueType TTF
- Fontをファイルから取得
- Htmlを使ったJLabelとJEditorPaneの無効化
- JEditorPaneのHTMLEditorKitにCSSを適用