Swing/EditorPaneListStyle のバックアップ(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/EditorPaneListStyle へ行く。
- 1 (2012-12-10 (月) 00:03:24)
- 2 (2014-12-04 (木) 02:41:25)
- 3 (2016-02-24 (水) 15:32:58)
- 4 (2017-07-18 (火) 16:08:36)
- 5 (2018-07-17 (火) 18:49:51)
- 6 (2018-08-29 (水) 19:00:00)
- 7 (2018-10-23 (火) 18:11:42)
- 8 (2020-10-23 (金) 17:54:56)
- 9 (2022-08-02 (火) 16:41:01)
- 10 (2022-08-20 (土) 22:15:25)
- 11 (2025-01-03 (金) 08:57:02)
- 12 (2025-01-03 (金) 09:01:23)
- 13 (2025-01-03 (金) 09:02:38)
- 14 (2025-01-03 (金) 09:03:21)
- 15 (2025-01-03 (金) 09:04:02)
- 16 (2025-06-19 (木) 12:41:37)
- 17 (2025-06-19 (木) 12:43:47)
TITLE:JEditorPaneのStyleSheetを使ってlist bulletを画像に変更
Posted by aterai at 2012-12-10
JEditorPaneのStyleSheetを使ってlist bulletを画像に変更
`JEditorPane
の
HTMLEditorKit
から
StyleSheet
を取得し、
list-style-image
を使って
List bullet
`を変更します。
- &jnlp;
- &jar;
- &zip;
サンプルコード
HTMLEditorKit htmlEditorKit = (HTMLEditorKit)pane.getEditorKit();
StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
String u = getClass().getResource(bullet).toString();
styleSheet.addRule(String.format("ul{list-style-image:url(%s);margin:0px 20px;", u));
//styleSheet.addRule("ul{list-style-type:circle;margin:0px 20px;}");
//styleSheet.addRule("ul{list-style-type:disc;margin:0px 20px;}");
//styleSheet.addRule("ul{list-style-type:square;margin:0px 20px;}");
//styleSheet.addRule("ul{list-style-type:decimal;margin:0px 20px;}");
View in GitHub: Java, Kotlin解説
- 上: `
Default
` - 下: `
ul{list-style-image:url(bullet.png);}
`- `
CSS
の
list-style-image
プロパティを使って、
bullet
`を画像に変更 - `
AlignmentY
`が中心にならない?ので、画像の下に余白を追加 - `
ul
のマージンも
margin:0px 20px;
`に変更
- `
- `
javax.swing.text.html.CSS
は、
list-style-type
プロパティも対応しているので、
circle
,
square
,
decimal
などが
bullet
`として使用できるが、サイズは固定styleSheet.addRule("ul{list-style-type:circle;margin:0px 20px;}"); //styleSheet.addRule("ul{list-style-type:disc;margin:0px 20px;}"); //styleSheet.addRule("ul{list-style-type:square;margin:0px 20px;}"); //styleSheet.addRule("ul{list-style-type:decimal;margin:0px 20px;}");
- `
javax.swing.text.html.CSS
は、
a:hover
などの擬似クラス(
pseudo-classes
)や、
:before
などの擬似要素(
pseudo elements
)に対応していないので、以下のように
list-style-type:none
として
:before
で任意の文字を
bullet
`に適用することができない
styleSheet.addRule("ul{list-style-type:none;margin:0px 20px;}");
styleSheet.addRule("ul li:before{content: "\u00BB";}");
- `
javax.swing.text.html.StyleSheet.ListPainter#drawShape(...)
などをオーバーライドできれば直接
bullet
`の形やサイズを変更できそうだが、コンストラクタがパッケージプライベート