Swing/HtmlDisable のバックアップの現在との差分(No.3)
- 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
サンプルコード
サンプルコード
#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
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
View in GitHub: Java, Kotlin解説
上記のサンプルでは、JLabel
などにputClientProperty("html.disable", Boolean.TRUE)
を設定することで、タグをレンダリングせずにそのまま文字列として表示しています。
解説
上記のサンプルでは、JLabel
などにputClientProperty("html.disable", Boolean.TRUE)
を設定することで、<html>
タグとしてレンダリングせずにそのまま文字列として表示しています。
- -
JLabel
に、putClientProperty("html.disable", Boolean.TRUE)
としても、そのJLabel
のJToolTip
には反映されないので、<html>
タグの中で文字実体参照を使っています。
-
JLabel
にputClientProperty("html.disable", Boolean.TRUE)
を設定しても、そのJLabel
のJToolTip
には反映されない-
<html>
タグの中で文字実体参照を使用して回避
-
- -
Html
レンダリングされた文字列を、setEnabled(false)
で無効化(灰色にする)する場合は、Htmlを使ったJLabelとJEditorPaneの無効化を参考にしてください。