Drawing only the region marked dirty in a Component

Hi

I have a plugin which needs to update the display often, but only tiny regions. Sometimes when the screen is updated, I have marked one tiny region in each of two different non-overlapping components as dirty, with repaint( Rectangle<int> ), and g.getClipBounds() returns a union of those two regions (which are far apart) in my paint method.

During testing I discovered that even though g.getClipBounds() returns a large rectangle, in reality I’m only allowed to draw in the small regions which I actually marked dirty (macOS), the rest is clipped away, even if it’s inside g.getClipBounds(). I could exploit that to optimize my drawing, however I can’t rely on remembering the regions I marked dirty (or could I?), as the system might ask for redrawing even when I haven’t marked it myself.

I thought perhaps declaring the components as opaque by calling setOpaque( true ); in the constructor would help, because then it wouldn’t need to repaint the parent component, so it wouldn’t actually need to make a union of the rectangles marked for redrawing in two different components. However, g.getClipBounds() still returns a union of the two rectangles.

Is there a way to obtain only the region marked dirty for each component, and would it be advisable to do so, or could it lead to compatibility issues? Perhaps I might override The drawing is fairly efficient now, so it’s not a big deal, but benchmarking/profiling shows that it’s still possible and beneficial to optimize further if I could do that.

See here: (SOLVED) Repaint() ignores opacity and repaints parent Component

1 Like