Swing/SelectedTextColor のバックアップ(No.6)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/SelectedTextColor へ行く。
- category: swing folder: SelectedTextColor title: JEditorPaneで選択した文字列の色反転を無効化 tags: [JEditorPane, HTMLEditorKit, StyleSheet] author: aterai pubdate: 2018-12-17T15:32:38+09:00 description: JEditorPaneで選択した文字のレンダリングに使用する色をnullにして選択文字色の変更を無効化します。 image: https://drive.google.com/uc?id=1Jv8dY71xTfQSscUwHdO-aekbqgRTFmfzwA
Summary
JEditorPane
で選択した文字のレンダリングに使用する色をnull
にして選択文字色の変更を無効化します。
Screenshot
Advertisement
サンプルコード
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
htmlEditorKit.setStyleSheet(styleSheet);
editor.setEditorKit(htmlEditorKit);
editor.setEditable(false);
editor.setSelectedTextColor(null);
editor.setSelectionColor(new Color(0x64_88_AA_AA, true));
editor.setBackground(new Color(0xEE_EE_EE));
View in GitHub: Java, Kotlin解説
- 上:
- 選択した文字をレンダリングする色は
LookAndFeel
でのデフォルト- たとえば
WindowsLookAndFeel
の場合選択文字色はColor.WHITE
になる
- たとえば
- 選択した文字をレンダリングする色は
- 下:
- 選択した文字のレンダリングを
JTextComponent#setSelectedTextColor(null)
で無効化してCSS
で設定した文字色を変更しないよう設定 - JTextComponent#setSelectedTextColor(Color) (Java Platform SE 8)のドキュメントには「色に
null
を設定することは、Color.black
と同じです。」と記述されているが、実際のJEditorPane
でnull
を設定すると選択文字色の変更は無効になる
- 選択した文字のレンダリングを
参考リンク
- JEditorPaneで選択色を半透明化
- JEditorPaneにソースコードをシンタックスハイライトして表示する
- Java access files in jar causes java.nio.file.FileSystemNotFoundException - Stack Overflow