Search code examples
javaswingjtextfield

Background image and JtextField


I want to set a background image for my JPannel which contains many JTextField and JButton (I used g.drawImage()), but the the components won't appear unless the mouse passes by. I can't make a JPanel for every component because I have too many of them.

Can anyone please help or point me into the right direction?


Solution

  • It sounds like either you've overridden paint or failed to call super.paintComponent when painting your image.

    Make sure that:

    1. You override paintComponent of your JPanel
    2. You call super.paintComponent before you perform any custom painting

    For example

    Also take a look at Painting in AWT and Swing and Performing Custom Painting for more details about painting in Swing