Hassan
Hassan

Reputation: 157

Repainting a single component among many

I have a question about repainting a graphic object in Java.

I have a JPanel on which I draw polygons or rectangles. When I double-click in a polygon, the polygon is identified and it is rendered by a certain color. However the way I'm doing this seems very ineffective because I repaint the entire panel while only one of them needs to be repainted. Now my question is:

Can we define and call a paint method for a Rectangle or GeneralPath (used as polygon)? If yes, would you please recommend a link to explain that?

Upvotes: 3

Views: 1933

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

See repaint(Rectangle).

Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.

Upvotes: 4

Related Questions