I have a JPanel which has a background image. To this panel, I add a JTextField, and set the background color to that that text field.
I expected the background to get the colour, but it is being overriden by the background image of panel.
Is this expected behavior? If not, how to get around it?
Check that your textfield is opaque.
Swing behaviour depends on many properties and layouts. You can try to debug your swing components with this tool and make some experiments with properties(background, opaque, …).