• Post Reply Bookmark Topic Watch Topic
  • New Topic

Painting Issues  RSS feed

 
Ed B.
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am writing a simple whiteboard application. The JFrame contains a JPanel which in turn contains a JToolbar and another JPanel which acts as a whiteboard. Now, if I draw something on the whiteboard, another toolbar is painted underneath the original toolbar. Following is the paintComponent method from the whiteboard jpanel:
public void paintComponent( Graphics g ) {
if(start) super.paintComponent(g);
if(oldPoint != null && newPoint != null)
g.drawLine( oldPoint.x, oldPoint.y, newPoint.x, newPoint.y );
}

Any help will be greatly appreciated.

Thanks
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super.paintComponent asks the JPanel to clear the background and fill it with its background color. If you do not make the call to super each time you will get artifacts left over from previous renderings. An alternative is to clear and paint the background yourself:

edit: typo
[ September 14, 2005: Message edited by: Craig Wood ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!