Making this paintbrush program I decided I want to clear the panel container (panel2 in the linked code). I used PanelName.setForeground(null) and it worked. What I’d like to know is if there are known drawbacks of this approach and other ways of removing graphics objects from the container.
Making this paintbrush program I decided I want to clear the panel container (
Share
If you override
paintComponent, you can clear itsGraphicsusingGraphics#clearRect. But overall, I prefer your approach because mine would require you to either subclassJPanel, or anonymously declare one.