• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JCheckBoxなどが無効な状態での文字色を変更
#navi(../)
#tags(JCheckBox, JComboBox, UIManager, Html, JLabel, JButton)
RIGHT:Posted by &author(aterai); at 2008-10-06
*JCheckBoxなどが無効な状態での文字色を変更 [#r5ed5917]
* JCheckBoxなどが無効な状態での文字色を変更 [#r5ed5917]
``JCheckBox``や``JComboBox``などのコンポーネントが無効な状態になった場合の文字色を変更します。

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

//#screenshot
#ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTLDPDIq4I/AAAAAAAAAW8/jt2A5D74G04/s800/DisabledTextColor.png)
#ref(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTLDPDIq4I/AAAAAAAAAW8/jt2A5D74G04/s800/DisabledTextColor.png)

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

**解説 [#l33eb0b4]
-``JCheckBox``
--``UIManager.put("CheckBox.disabledText", Color.RED)``
---``MetalLookAndFeel``でのみ?、反映される
-``JCheckBox`` + ``html``
--``<html>``タグを使った場合、``setEnable``にかかわらず、文字色は変更不可([http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4740519 Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false)])を利用
---参考:[http://forums.sun.com/thread.jspa?threadID=5328889 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``でのみ?、反映される
** 解説 [#l33eb0b4]
- ``JCheckBox``
-- ``UIManager.put("CheckBox.disabledText", Color.RED)``
--- ``MetalLookAndFeel``でのみ?、反映される
- ``JCheckBox`` + ``html``
-- ``<html>``タグを使った場合、``setEnable``にかかわらず、文字色は変更不可([http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4740519 Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false)])を利用
---参考:[https://forums.oracle.com/message/5740059 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(http://lh5.ggpht.com/_9Z4BYR88imo/TQTLFT1HGFI/AAAAAAAAAXA/W5L-yIFc61E/s800/DisabledTextColor1.png)
#ref(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTLFT1HGFI/AAAAAAAAAXA/W5L-yIFc61E/s800/DisabledTextColor1.png)

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