Swing/HtmlDisable のバックアップの現在との差分(No.2)
TITLE:JLabelなどのHtmlレンダリングを無効化
JLabelなどのHtmlレンダリングを無効化
Posted by terai at 2008-04-21- category: swing folder: HtmlDisable title: JLabelなどのHtmlレンダリングを無効化 tags: [JLabel, Html, JToolTip] author: aterai pubdate: 2008-04-21T13:43:08+09:00 description: JLabelなどのHtmlレンダリングを無効化して、タグ文字列をそのまま表示します。 image:
概要
JLabel
などのHtml
レンダリングを無効化して、タグ文字列をそのまま表示します。
Screenshot
Advertisement
概要
JLabelなどのHtmlレンダリングを無効化して、タグ文字列をそのまま表示します。- &jnlp;
- &jar;
- &zip;
#screenshot
サンプルコード
#spanend
#spandel
label1.putClientProperty("html.disable", Boolean.TRUE);
#spanend
#spandel
label1.setText("<html><font color=red>Html Test</font></html>");
#spanend
#spandel
label1.setToolTipText("<html><html><font color=red>Html Test</font></html></html>");
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
label.putClientProperty("html.disable", Boolean.TRUE);
#spanend
#spanadd
label.setText("<html><font color=red>Html Test</font></html>");
#spanend
#spanadd
label.setToolTipText("<html><html><font color=red>Html Test</font></html></html>");
#spanend
解説
上記のサンプルでは、JLabelなどにputClientProperty("html.disable", Boolean.TRUE)を設定することで、タグをレンダリングせずにそのまま文字列として表示しています。解説
上記のサンプルでは、JLabel
などにputClientProperty("html.disable", Boolean.TRUE)
を設定することで、<html>
タグとしてレンダリングせずにそのまま文字列として表示しています。
- - putClientProperty("html.disable", Boolean.TRUE)としても、ToolTipには反映されないので、<html>タグの中で文字実体参照を使っています。
-
JLabel
にputClientProperty("html.disable", Boolean.TRUE)
を設定しても、そのJLabel
のJToolTip
には反映されない-
<html>
タグの中で文字実体参照を使用して回避
-
- - Htmlレンダリングされた文字列を、setEnabled(false)で無効化(灰色にする)する場合は、Htmlを使ったJLabelとJEditorPaneの無効化を参考にしてください。