Swing/StyleSheet のバックアップの現在との差分(No.11)
- category: swing folder: StyleSheet title: JEditorPaneのHTMLEditorKitにCSSを適用 tags: [JEditorPane, StyleSheet, HTMLEditorKit] author: aterai pubdate: 2009-07-20T14:20:10+09:00 description: JEditorPaneにStyleSheetを追加したHTMLEditorKitを設定します。 image:
概要
JEditorPane
にStyleSheet
を追加したHTMLEditorKit
を設定します。
Screenshot
Advertisement
サンプルコード
StyleSheet styleSheet = new StyleSheet();
styleSheet.addRule("body {font-size: 12pt;}");
styleSheet.addRule(".highlight {color: red; background: green}");
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
htmlEditorKit.setStyleSheet(styleSheet);
JEditorPane editor = new JEditorPane();
editor.setEditorKit(htmlEditorKit);
editor.setText(makeTestHtml());
View in GitHub: Java, Kotlin解説
上記のサンプルでは、JEditorPane
にHTMLEditorKit
を適用してHTML
を表示するよう設定し、クラス名が.highlight
になっている要素の文字色と背景色をCSS
で変更しています。
-
JEditorPane
にHTMLEditorKit
を適用してHTML
を表示するよう設定 - クラス名が
.highlight
になっている要素の文字色と背景色をCSS
で変更-
HTMLEditorKit
のCSS
で色は3
桁表記(color: #RGB
) には対応していない -
6
桁表記color:#RRGGBB
は問題なく使用可
-
参考リンク
- Java Swing「JEditorPane」メモ(Hishidama's Swing-JEditorPane Memo)
- Java Swing「JEditorPane」メモ(Hishidama's Swing-JEditorPane Memo)
- Swing - HTMLEditorKit and CSS
- StyleSheet (Java Platform SE 8)
- How to add stylesheet information to a JEditorPane | alvinalexander.com
- How to add stylesheet information to a JEditorPane | alvinalexander.com
- GraphicsEnvironmentにFontを登録して使用する
- Rhinoでgoogle-prettify.jsを実行する