概要
JCheckBox
やJComboBox
などのコンポーネントが無効な状態になった場合の文字色を変更します。
サンプルコード
UIManager.put("CheckBox.disabledText", Color.RED);
JCheckBox cbx1 = new JCheckBox("default", true);
JCheckBox cbx2 = new JCheckBox("<html>html tag</html>", true);
View in GitHub: Java, Kotlin解説
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
でのみ反映
参考リンク
- Bug ID: 4740519 HTML JLabel not greyed out on setEnabled(false)
- Swing - How to disable a JCheckBox and leave the text the original color?
- Bug ID: 4783068 Components with HTML text should gray out the text when disabled
- Htmlを使ったJLabelとJEditorPaneの無効化