• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JCheckBoxなどの編集不可文字色を変更
#navi(../)
*JCheckBoxなどの編集不可文字色を変更 [#kf3c0d46]
Posted by [[terai]] at 2008-10-06
---
category: swing
folder: DisabledTextColor
title: JCheckBoxなどが無効な状態での文字色を変更
tags: [JCheckBox, JComboBox, UIManager, Html, JLabel, JButton]
author: aterai
pubdate: 2008-10-06T14:59:33+09:00
description: JCheckBoxやJComboBoxなどのコンポーネントが無効な状態になった場合の文字色を変更します。
image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTLDPDIq4I/AAAAAAAAAW8/jt2A5D74G04/s800/DisabledTextColor.png
---
* 概要 [#summary]
`JCheckBox`や`JComboBox`などのコンポーネントが無効な状態になった場合の文字色を変更します。

#contents
#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTLDPDIq4I/AAAAAAAAAW8/jt2A5D74G04/s800/DisabledTextColor.png)

**概要 [#mdabb408]
JCheckBoxやJComboBoxなどのコンポーネントが編集不可になった場合の文字色を変更します。

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

#screenshot

**サンプルコード [#q9537f41]
#code{{
* サンプルコード [#sourcecode]
#code(link){{
UIManager.put("CheckBox.disabledText", Color.RED);
JCheckBox cbx1 = new JCheckBox("default", true);
JCheckBox cbx2 = new JCheckBox("<html>html tag</html>", true);
JCheckBox cbx2 = new JCheckBox("<html>html <span style='color:red'>tag");
}}

**解説 [#l33eb0b4]
-JCheckBox
--UIManager.put("CheckBox.disabledText", Color.RED)
---Metal Look&Feel でのみ?、反映される
-JCheckBox(html)
--<html>タグを使った場合、setEnableにかかわらず、文字色は変更不可([[Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false)>http://bugs.sun.com/view_bug.do?bug_id=4740519]])を利用
---参考:[[Swing - How to disable a JCheckBox and leave the text the original color?>http://forums.sun.com/thread.jspa?threadID=5328889]]のMichael_Dunn さんの投稿
---[[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]]
-JComboBox
--UIManager.put("ComboBox.disabledForeground", Color.GREEN);
-JComboBox(html)
--レンダラーで文字色を変更
-JLabel
--UIManager.put("Label.disabledForeground", Color.ORANGE);
-JButton
--UIManager.put("Button.disabledText", Color.YELLOW)
---Metal Look&Feel でのみ?、反映される
* 解説 [#explanation]
- `JCheckBox`
-- `UIManager.put("CheckBox.disabledText", Color.RED)`
--- `MetalLookAndFeel`でのみ有効
- `JCheckBox` + `html`
-- `JDK 1.7.0`で以下の動作は修正されて、無効化で`HTML`文字列もグレーになる
--- [https://bugs.openjdk.org/browse/JDK-4783068 Bug ID: 4783068 Components with HTML text should gray out the text when disabled]
-- %%`<html>`タグを使った場合、文字色は常に不変で`isEnabled()`の状態に依存しない([https://bugs.openjdk.org/browse/JDK-4740519 Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false)])を利用%%
--- 参考: [https://community.oracle.com/thread/1359798 Swing - How to disable a JCheckBox and leave the text the original color?]のMichael_Dunn さんの投稿
--- [[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]]
- `JComboBox`
-- `UIManager.put("ComboBox.disabledForeground", Color.GREEN);`
- `JComboBox` + `html`
-- レンダラーで文字色を変更
- `JComboBox`(`Editable`)
-- `EditorComponent`を取得して、`editor.setDisabledTextColor(Color.PINK);`を設定
- `JLabel`
-- `UIManager.put("Label.disabledForeground", Color.ORANGE);`
- `JButton`
-- `UIManager.put("Button.disabledText", Color.YELLOW)`
--- `MetalLookAndFeel`でのみ反映

#screenshot(,screenshot1.png)
#ref(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTLFT1HGFI/AAAAAAAAAXA/W5L-yIFc61E/s800/DisabledTextColor1.png)

//**参考リンク
**コメント [#w6daf1af]
* 参考リンク [#reference]
- [https://bugs.openjdk.org/browse/JDK-4740519 &#91;JDK-4740519&#93; HTML JLabel not greyed out on setEnabled(false) - Java Bug System]
- [https://community.oracle.com/thread/1359798 Swing - How to disable a JCheckBox and leave the text the original color?]
- [https://bugs.openjdk.org/browse/JDK-4783068 &#91;JDK-4783068&#93; Components with HTML text should gray out the text when disabled - Java Bug System]
- [[Htmlを使ったJLabelとJEditorPaneの無効化>Swing/DisabledHtmlLabel]]
- [https://bugs.openjdk.org/browse/JDK-7093691 &#91;JDK-7093691&#93; Nimbus LAF: disabled JComboBox using renderer has bad font color - Java Bug System]
- [[JButtonが無効な状態でのhtmlテキスト色を変更する>Swing/ButtonDisabledHtmlText]]

* コメント [#comment]
#comment
#comment