aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Why am I getting a copy of a button in my JPanel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why am I getting a copy of a button in my JPanel?" Watch "Why am I getting a copy of a button in my JPanel?" New topic
Author

Why am I getting a copy of a button in my JPanel?

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

You will notice that I only add one button to my frame, but when I add the animation loop in, another button mysteriously appears on the left!

What's going on?



Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

More bizarreness if I put it on the WEST:



Similar things happen for NORTH and SOUTH as well.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

If you override the paintComponent method, you have to be careful. Call super.paintComponent(g), otherwise :
API wrote:
If you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts.


[My Blog]
All roads lead to JavaRanch
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Cool, thanks. That works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why am I getting a copy of a button in my JPanel?