• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JEditorPaneのHTMLEditorKitにCSSを適用
#navi(../)
RIGHT:Posted by [[terai]] at 2009-07-20
*JEditorPaneのHTMLEditorKitにCSSを適用 [#y336d1e1]
JEditorPaneにStyleSheetを追加したHTMLEditorKitを設定します。

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

#screenshot

**サンプルコード [#p2576f29]
#code{{
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());
}}

**解説 [#f80e2a15]
上記のサンプルでは、クラス名が.highlightの要素の文字色と背景色をCSSで変更しています。

**参考リンク [#kc26b056]
-[[Java Swing「JEditorPane」メモ(Hishidama's Swing-JEditorPane Memo)>http://www.ne.jp/asahi/hishidama/home/tech/java/swing/JEditorPane.html]]
-[[Swing - HTMLEditorKit and CSS>http://forums.sun.com/thread.jspa?threadID=580677]]

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