• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JEditorPaneのHTMLEditorKitにCSSを適用
#navi(../)
#tags(JEditorPane, StyleSheet, HTMLEditorKit)
RIGHT:Posted by &author(aterai); at 2009-07-20
*JEditorPaneのHTMLEditorKitにCSSを適用 [#y336d1e1]
``JEditorPane``に``StyleSheet``を追加した``HTMLEditorKit``を設定します。
---
title: JEditorPaneのHTMLEditorKitにCSSを適用
tags: [JEditorPane, StyleSheet, HTMLEditorKit]
author: aterai
pubdate: 2009-07-20T14:20:10+09:00
description: JEditorPaneにStyleSheetを追加したHTMLEditorKitを設定します。
---
* 概要 [#y336d1e1]
`JEditorPane`に`StyleSheet`を追加した`HTMLEditorKit`を設定します。

-&jnlp;
-&jar;
-&zip;
#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTT6cwbhCI/AAAAAAAAAlM/PsSYnlumJJg/s800/StyleSheet.png)

//#screenshot
#ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTT6cwbhCI/AAAAAAAAAlM/PsSYnlumJJg/s800/StyleSheet.png)

**サンプルコード [#p2576f29]
* サンプルコード [#p2576f29]
#code(link){{
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``で変更しています。
* 解説 [#f80e2a15]
上記のサンプルでは、クラス名が`.highlight`の要素の文字色と背景色を`CSS`で変更しています。

**参考リンク [#kc26b056]
-[http://www.ne.jp/asahi/hishidama/home/tech/java/swing/JEditorPane.html Java Swing「JEditorPane」メモ(Hishidama's Swing-JEditorPane Memo)]
-[https://forums.oracle.com/forums/thread.jspa?messageID=5876548 Swing - HTMLEditorKit and CSS]
-[http://docs.oracle.com/javase/jp/6/api/javax/swing/text/html/StyleSheet.html StyleSheet (Java Platform SE 6)]
* 参考リンク [#kc26b056]
- [http://www.ne.jp/asahi/hishidama/home/tech/java/swing/JEditorPane.html Java Swing「JEditorPane」メモ(Hishidama's Swing-JEditorPane Memo)]
- [https://forums.oracle.com/thread/1392908 Swing - HTMLEditorKit and CSS]
- [http://docs.oracle.com/javase/jp/6/api/javax/swing/text/html/StyleSheet.html StyleSheet (Java Platform SE 6)]
-- [http://docs.oracle.com/javase/jp/6/api/javax/swing/text/html/CSS.html 対応しているCSSプロパティ一覧 - CSS (Java Platform SE 6)]
-[http://www.devdaily.com/blog/post/jfc-swing/how-add-style-stylesheet-jeditorpane-example-code/ How to add stylesheet information to a JEditorPane (jfc/swing)]
-[[GraphicsEnvironmentにFontを登録して使用する>Swing/RegisterFont]]
-[[Rhinoでgoogle-prettify.jsを実行する>Tips/GooglePrettifyRhino]]
- [http://www.devdaily.com/blog/post/jfc-swing/how-add-style-stylesheet-jeditorpane-example-code/ How to add stylesheet information to a JEditorPane (jfc/swing)]
- [[GraphicsEnvironmentにFontを登録して使用する>Swing/RegisterFont]]
- [[Rhinoでgoogle-prettify.jsを実行する>Tips/GooglePrettifyRhino]]

**コメント [#y67a16b3]
- ``HTMLEditorKit``の``CSS``で、色は``3``桁表記(``color: #RGB``) には対応していない?(``6``桁表記 ``color:#RRGGBB``は問題なく使用可) -- [[aterai]] &new{2012-05-28 (月) 17:52:03};
* コメント [#y67a16b3]
#comment
- `HTMLEditorKit`の`CSS`で、色は`3`桁表記(`color: #RGB`) には対応していない?(`6`桁表記 `color:#RRGGBB`は問題なく使用可) -- &user(aterai); &new{2012-05-28 (月) 17:52:03};

#comment