I've asked this before but nobody seemed to know the answer. I have a component that draws a vertical line playhead but it calls repaint on the parent. I just want to draw the line

Calling repaint on the parent over and over again during playback is causing massive CPU usage. Somebody mentioned setOpaque but all that seems to do is make things invisible or black.

I think I may need to use getClipBounds() but not sure where, why, or how.

As always, thanks in advance!

1 Like

You can’t avoid redrawing the parent component, since the part that was occluded by your playhead component has to be drawn. If you set the bounds of the playhead instead of calling repaint(), it is taken care of, that the system will call repaint only with the minimal necessary area.

You can set the parent component to buffered, so instead of calling the paint() routine, it uses a buffer image to restore the dirty area.

See Component::setBufferedToImage (true)

1 Like

So let’s pretend I’m an idiot. Do I replace “paint()” in the playhead component to " “setBufferedToImage(true)”? That’s not working and doesn’t make sense to me.

Do I still call repaint() in the component, and then in my top level write “setBufferedToImage(true)” inside the paint function or something?

It is a setting of the parent component, so when you create it, you call once setBufferedToImage (true).

But you caught me, I don’t actually know, when it uses the buffer, and how it determines, that it needs to call the actual paint() method. The docs say, if you call repaint() on the parent, it will invalidate and call repaint(). But I “assume”, that just moving your component with setBounds(), it uses the cache…?

1 Like

The most important thing is to make sure your parent component selectively only paints stuff that intersects the requested rectangle. If you have lots of data on a long timeline (i.e. some track data), be sure it can be drawn selectively.

1 Like