Components: painting and erasing

Hi everybody.

A couple of times now, I have had this problem. After having drawn something in a component, for instance by g.drawLine(…) or similar, I want to erase it again. Say the line I draw has moved, and I need to draw it somewhere else - how do I “erase” the old one?

Painting over the entire component only works, if the component is opaque - say I have a completely transparent component, except the line I am drawing… How would I go about erasing the “former” line? Obviously, it doesn’t work to draw the line with a transparent Colour… Any thought?

  • A

Woah… you’re pretty wide of the mark there! Go and have a good read of the comments for Component::paint() and repaint(), and maybe look at the way the demo code draws moving objects - and forget about ‘erasing’ anything, it’s not like drawing on a piece of paper!

Heh, no need to “woah” - I thought so. I don’t usually have problems with this, but juuust once in a while. This time I think it is due to some overloading of texteditor’s paint method, and the drawing of labels in LookAndFeel. The caret in the texteditor of a slider acts up… Something gets confounded there. I will check up on it, thanks anyway :slight_smile:

  • A

It is a bit confusing until you get your head around the whole paint/repaint thing. TBH it’s a paradigm that will probably disappear eventually, and be replaced by more declarative models like flash/dhtml/xml use.