JEditorPaneのHTMLEditorKitにCSSを適用
Total: 8549
, Today: 1
, Yesterday: 0
Posted by aterai at
Last-modified:
概要
JEditorPane
にStyleSheet
を追加したHTMLEditorKit
を設定します。
サンプルコード
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 all解説
上記のサンプルでは、JEditorPane
にHTMLEditorKit
を適用してHTML
を表示するよう設定しクラス名が.highlight
になっている要素の文字色と背景色をCSS
で変更しています。
参考リンク
- 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
- GraphicsEnvironmentにFontを登録して使用する
- Rhinoでgoogle-prettify.jsを実行する