0

I have written a custom component that extends JPanel and overridden its paint() method. Now I can see that this method is called once per 10 milliseconds when the component is displaying. Nothing changes in the component but paint() is still called. I have several calls repaint() but none of them is called actually. How to know what is causing such frequent updates?

UPDATE! There was "bug" in my code. I was updating inner components form paint() method so it was the root cause of continuous repainting. But still, the question is not answered: how to understand what supplies events to the queue?

VDanyliuk
  • 1,049
  • 8
  • 23

2 Answers2

1

how to understand what supplies events to the queue?

Whenever a property of a Swing component is changed the component will automatically invoke repaint() on itself. The paint request is passed to the RepaintManager.

The RepaintManager will then consolidate multiple repaint requests into a single painting of all components. The consolidation is done to make painting more efficient.

So the individual component that made the request is not available because in many cases multiple components will make the repaint request at the same time.

You can read Painting in AWT and Swing for a more detailed explanation.

camickr
  • 321,443
  • 19
  • 166
  • 288
0

using debug make a break point in the paint() function and when it called you can watch the stack trace of the call back

Hazem Ashraf
  • 310
  • 2
  • 8