1

I am using a custom JPanel with a background image. I have put the background image by overriding the panel's paintComponent() method. The layout of the panel is set to GridBagLayout. Now I am trying to add another JPanel to it on which I am drawing a rectangle.

When I am trying to do that the rectangle is drawn at arbitrary positions and its duplicates are also being drawn. When I remove the background image of the first panel everything works fine.

How to solve this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
arvind1988
  • 21
  • 5
  • 3
    no ideas, for better help sooner post an [SSCCE](http://sscce.org/) demonstrated a.m. issue, with [hardcoded BufferedImage](http://stackoverflow.com/a/7944388/714968) – mKorbel Nov 26 '12 at 16:34
  • 2
    "If you do not honor the [opaque](http://www.oracle.com/technetwork/java/painting-140037.html#props) property (by calling `calling super.paintComponent()`) you will likely see visual artifacts."—`JComponent` – trashgod Nov 26 '12 at 19:38
  • I am calling super.paintComponent() but the problem continues – arvind1988 Nov 27 '12 at 04:34

0 Answers0