0

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?

ghassen92
  • 305
  • 1
  • 2
  • 12
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson May 13 '15 at 00:27

1 Answers1

2

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

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • It appears "cannot find symbol" when i write super.paintComponent , I'm new actually to java ... – ghassen92 May 12 '15 at 23:24
  • 1
    Then I "assume" that you're overriding `paint` of a `JFrame` or other top level container, which you shouldn't do. Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer May 12 '15 at 23:26
  • Oh, and where are you "writing" `super.paintComponent`? – MadProgrammer May 12 '15 at 23:27
  • 1
    In the `override paintComponent` method. – Shane van Wyk May 13 '15 at 00:09
  • Plus one to @MadProgrammer for attempting to answer this, and you for answering a question that was asked, but voted to close for 'lack of a runnable example' .. – Andrew Thompson May 13 '15 at 00:32
  • Unless you can provide a runnable example which demonstrates your problem, I'm unsure how much more support I can provide, as it's all guess work based on assumptions – MadProgrammer May 13 '15 at 00:51
  • 1
    @AndrewThompson I'm to bloody nice for my own good :P – MadProgrammer May 13 '15 at 01:13