Change color SetEnabled

My question is this: By default, the color change to give JTextField setEnabled (false), for example, is black and checked with the UIManager results, but there were no suggestions.

Hey.

+3
source share
1 answer

To change the color of a disabled background, try the following:

UIManager.put("TextField.disabledBackground", Color.GRAY);

You can change the color of the disabled text with setDisabledTextColor , i.e .:

textField.setDisabledTextColor(Color.GRAY);

EDIT: Enable SSCCE

import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class TestDisabledTextField {

    public static void main(String[] args) {
        UIManager.put("TextField.disabledBackground", Color.YELLOW);

        JTextField textField = new JTextField("Disabled text field", 15);
        textField.setEnabled(false);
        textField.setDisabledTextColor(Color.RED);

        JPanel panel = new JPanel();
        panel.add(textField);

        JOptionPane.showMessageDialog(null, panel);
    }
}
+6
source

All Articles