Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java JPanel bug  RSS feed

 
Brendan Fosberry
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. Im having a weird bug with my JPanels. I call them to repaint seperately from a control class. One panel is larger than the other, near the top left corner, both classes extend JPanel in different ways. The second class is further to the right, but Im having weird issues like whenever my second panel repaints, it ALSO repaints itself on my first jpanel at 0,0. This also happens with sliders, buttons and menu items. Its strange. Any thoughts? I cant think what Im doing wrong.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Err, there's a forum for Swing/etc... but anyway, when you override a painting method like paint, or better paintComponent, be sure to call the superclass's version first:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using
panel.repaint()

try just
repaint()//if control class extends JFrame
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT.
 
Brendan Fosberry
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm. Well I was originally using super.paintcomponent, but every time I did that the screen would flash white...and as Im making a running animation of a flight, out of still photos, it wont be very good if some clients have an epileptic attack. I cant think how to sort that problem out after this one. lol.

btw sorry for posting in the wrong forum.

---------------------edit

Thanks guys! that fixed the problem! Now my only problem is with my main panel. Every time it changes picture it goes blank first, and it wont display anything at high speeds. Its probably something with my image lodaing technique. It doesnt happen on my other panel regardless of speed. thanks for the help guys.
[ January 19, 2006: Message edited by: Brendan Fosberry ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!