Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel repaint(): what does it do inside?

 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have no problem using repaint(). But I'm curious to know what it does inside.
Does it simply call the paintComponent() method again or do something special?
I can't imagine how the program will know what and how to repaint if it doesn't call my overridden paintComponent() method

Thanks for any explanations.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know that you have the source of all the JDK classes on your hard disk? Look in your JDK installation folder for a file src.zip.

You can see from the API that the repaint() method is inherited from Component. In Component, it calls repaint(long tm, int x, int y, int width, int height) with appropriate parameters. For AWT classes, that method either calls the same method of the Component's Container, or posts a PaintEvent to the EventQueue.

JComponent overrides the latter method to add a "dirty region" to the Swing RepaintManager, which pushes the painting requirement to the SystemEventQueue via SystemEventQueueUtilities.

Oh, and the outcome will be to invoke paint(...). Read the API for JComponent#paint(...) to see what that does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic