Swing/DisabledTextColor のバックアップの現在との差分(No.1)
TITLE:JCheckBoxなどの編集不可文字色を変更
JCheckBoxなどの編集不可文字色を変更
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:
概要
JCheckBox
やJComboBox
などのコンポーネントが無効な状態になった場合の文字色を変更します。
Screenshot
Advertisement
概要
JCheckBoxやJComboBoxなどのコンポーネントが編集不可になった場合の文字色を変更します。- &jnlp;
- &jar;
- &zip;
#screenshot
サンプルコード
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
UIManager.put("CheckBox.disabledText", Color.RED);
JCheckBox cbx1 = new JCheckBox("default", true);
#spandel
JCheckBox cbx2 = new JCheckBox("<html>html tag</html>", true);
#spanend
#spanadd
JCheckBox cbx2 = new JCheckBox("<html>html <span style='color:red'>tag");
#spanend
解説
- JCheckBox
- UIManager.put("CheckBox.disabledText", Color.RED)
- Metal Look&Feel でのみ?、反映される
- UIManager.put("CheckBox.disabledText", Color.RED)
- JCheckBox(html)
- <html>タグを使った場合、setEnableにかかわらず、文字色は変更不可(Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false))を利用
- 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 でのみ?、反映される
- UIManager.put("Button.disabledText", Color.YELLOW)
解説
-
JCheckBox
-
UIManager.put("CheckBox.disabledText", Color.RED)
-
MetalLookAndFeel
でのみ有効
-
-
-
JCheckBox
+html
-
JDK 1.7.0
で以下の動作は修正されて、無効化でHTML
文字列もグレーになる -
<html>
タグを使った場合、文字色は常に不変でisEnabled()
の状態に依存しない(Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false))を利用
-
-
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
でのみ反映
-
-
コメント
参考リンク
- [JDK-4740519] HTML JLabel not greyed out on setEnabled(false) - Java Bug System
- Swing - How to disable a JCheckBox and leave the text the original color?
- [JDK-4783068] Components with HTML text should gray out the text when disabled - Java Bug System
- Htmlを使ったJLabelとJEditorPaneの無効化
- [JDK-7093691] Nimbus LAF: disabled JComboBox using renderer has bad font color - Java Bug System
- JButtonが無効な状態でのhtmlテキスト色を変更する