0

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)

Community
  • 1
  • 1
searchfunction
  • 109
  • 2
  • 9

1 Answers1

1

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.

Community
  • 1
  • 1
npinti
  • 51,780
  • 5
  • 72
  • 96
  • this only works if I create textfield by hand? What about drag and drop ? – searchfunction Jan 15 '14 at 10:25
  • @searchfunction: `pane` in this case is the parent component which will hold all the text fields, so the code does not really care how you add the components. – npinti Jan 15 '14 at 10:30
  • oh ok..i got it to work...thanks. Just some error in ur code. replace the line to ((JTextField)c).setDisabledTextColor(Color.BLACK); – searchfunction Jan 15 '14 at 10:41