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>&lt;html&gt;&lt;font color=red&gt;Html Test&lt;/font&gt;&lt;/html&gt;</html>");

解説

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


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

コメント