The Need To Restore Graphics Original State When Overwritten paint or paintComponent
I realize most of the Java code to overwritten paint or paintComponent, most of them doesn't restore the old state of graphics object, after they had change the state of graphics object. For example, setStroke, setRenderingHint... I was wondering whether it is a good practice that we restore back the old state of graphics object, before returning from the method. For example public void paintComponent(Graphics g) { super.paintComponet(g); Stroke oldStroke = g.getStroke(); g.setStroke(newStroke); // Do drawing operation. g.setStroke(oldStroke); } Is this a good practice? Or it is over done? You