Change Color SetEnabled

10.3k views Asked by At

My question is this: Default change the color to give a JTextField setEnabled (false) for example is black and proven with UIManager results but have not had any suggestions.

Greetings.

1

There are 1 answers

3
tenorsax On BEST ANSWER

To change disabled background color try this:

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

You can change disabled text color using setDisabledTextColor, i.e.:

textField.setDisabledTextColor(Color.GRAY);

EDIT: include 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);
    }
}