This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 14687
    
  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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why am I getting a copy of a button in my JPanel?
 
Similar Threads
Triggering an animation from a button
Event Problems: Need Help
JFrame problem
GUI Problem
Animation in Java