TITLE:JLabelなどのHtmlレンダリングを無効化
#navi(../)
*JLabelなどのHtmlレンダリングを無効化 [#w86356de]
Posted by [[terai]] at 2008-04-21

#contents

**概要 [#qcd078d5]
JLabelなどのHtmlレンダリングを無効化して、タグ文字列をそのまま表示します。

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

#screenshot

**サンプルコード [#l921f158]
#code{{
label1.putClientProperty("html.disable", Boolean.TRUE);
label1.setText("<html><font color=red>Html Test</font></html>");
label1.setToolTipText("<html>&lt;html&gt;&lt;font color=red&gt;Html Test&lt;/font&gt;&lt;/html&gt;</html>");
}}

**解説 [#w8cdc1ca]
上記のサンプルでは、JLabelなどにputClientProperty("html.disable", Boolean.TRUE)を設定することで、タグをレンダリングせずにそのまま文字列として表示しています。

----
putClientProperty("html.disable", Boolean.TRUE)としても、ToolTipには反映されないので、<html>タグの中で文字実体参照を使っています。

----
Htmlレンダリングされた文字列を、setEnabled(false)で無効化(灰色にする)する場合は、[[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]]を参考にしてください。

//**参考リンク
**コメント [#n441a4f7]
#comment