Search code examples
javaswingcolorsjtextfield

JTextField - how to set background color?


I want to know how to set color of my JTextField component. I tried this way:

setBackground(Color.white)

and it sets a white color, but when the field is marked. I want the field to be white immediately after my program starts and without any user interaction.

Thanks for help!


Solution

  • You can change background color by this code

    textField.setBackground(Color.RED);
    

    You should also check this Change JTextField enabled background color