searchfunction
searchfunction

Reputation: 109

Java Set default disabled textfield text to black instead of grey

Problem

I have a problem where by I have to disable 10 textfield but the default text become grey. I know we can use

textfield1.setDisabledTextColor(Color c)

. But I will have to do this for all 10 textfield, which I find it irreverent.

Is there another option for me to change the UI manager so by default its black? btw, I am using netbean GUI builder.

Code

txtField1.setEnabled(false); txtField1.setDisabledTextColor(Color.BLACK)

Upvotes: 0

Views: 2322

Answers (1)

npinti
npinti

Reputation: 52185

Taking this previous SO question as an example, you could do something like so:

for (Component c : pane.getComponents()) {
    if (c instanceof JTextField) { 
       ((JTextField)c).setEnabled(false); 
       ((JTextField)c).setDisabledTextColor(Color.BLACK);
    }
}

I think that this should give you more control over your components.

Upvotes: 1

Related Questions