Swing/HtmlDisable のバックアップ(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/HtmlDisable へ行く。
- 1 (2008-04-21 (月) 13:43:08)
- 2 (2008-08-08 (金) 12:08:32)
- 3 (2014-10-03 (金) 14:12:15)
- 4 (2015-11-08 (日) 16:16:18)
- 5 (2017-05-09 (火) 17:54:31)
- 6 (2018-04-27 (金) 21:58:23)
- 7 (2020-04-23 (木) 18:41:26)
- 8 (2021-10-28 (木) 03:20:18)
- 9 (2025-01-03 (金) 08:57:02)
- 10 (2025-01-03 (金) 09:01:23)
- 11 (2025-01-03 (金) 09:02:38)
- 12 (2025-01-03 (金) 09:03:21)
- 13 (2025-01-03 (金) 09:04:02)
TITLE:JLabelなどのHtmlレンダリングを無効化
JLabelなどのHtmlレンダリングを無効化
Posted by terai at 2008-04-21
概要
JLabelなどのHtmlレンダリングを無効化して、タグ文字列をそのまま表示します。
- &jnlp;
- &jar;
- &zip;
#screenshot
サンプルコード
label1.putClientProperty("html.disable", Boolean.TRUE);
label1.setText("<html><font color=red>Html Test</font></html>");
label1.setToolTipText("<html><html><font color=red>Html Test</font></html></html>");
解説
上記のサンプルでは、JLabelなどにputClientProperty("html.disable", Boolean.TRUE)を設定することで、タグをレンダリングせずにそのまま文字列として表示しています。
putClientProperty("html.disable", Boolean.TRUE)としても、ToolTipには反映されないので、<html>タグの中で文字実体参照を使っています。
Htmlレンダリングされた文字列を、setEnabled(false)で無効化(灰色にする)する場合は、Htmlを使ったJLabelとJEditorPaneの無効化を参考にしてください。