diff options
Diffstat (limited to 'libjava/classpath/javax/swing/JComponent.java')
-rw-r--r-- | libjava/classpath/javax/swing/JComponent.java | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/libjava/classpath/javax/swing/JComponent.java b/libjava/classpath/javax/swing/JComponent.java index b217bc78867..66c562d110b 100644 --- a/libjava/classpath/javax/swing/JComponent.java +++ b/libjava/classpath/javax/swing/JComponent.java @@ -2039,19 +2039,10 @@ public abstract class JComponent extends Container implements Serializable continue; boolean translated = false; - try - { - g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height); - g.translate(bounds.x, bounds.y); - translated = true; - children[i].paint(g); - } - finally - { - if (translated) - g.translate(-bounds.x, -bounds.y); - g.setClip(oldClip); - } + Graphics g2 = g.create(bounds.x, bounds.y, bounds.width, + bounds.height); + children[i].paint(g2); + g2.dispose(); } g.setClip(originalClip); } @@ -2183,13 +2174,19 @@ public abstract class JComponent extends Container implements Serializable // Paint on the offscreen buffer. Component root = getRoot(this); - Image buffer = rm.getOffscreenBuffer(this, root.getWidth(), - root.getHeight()); + Image buffer = rm.getVolatileOffscreenBuffer(this, root.getWidth(), + root.getHeight()); + + // The volatile offscreen buffer may be null when that's not supported + // by the AWT backend. Fall back to normal backbuffer in this case. + if (buffer == null) + buffer = rm.getOffscreenBuffer(this, root.getWidth(), root.getHeight()); + //Rectangle targetClip = SwingUtilities.convertRectangle(this, r, root); Point translation = SwingUtilities.convertPoint(this, 0, 0, root); Graphics g2 = buffer.getGraphics(); - g2.translate(translation.x, translation.y); - g2.setClip(r.x, r.y, r.width, r.height); + clipAndTranslateGraphics(root, this, g2); + g2.clipRect(r.x, r.y, r.width, r.height); g2 = getComponentGraphics(g2); isPaintingDoubleBuffered = true; try @@ -2209,6 +2206,26 @@ public abstract class JComponent extends Container implements Serializable } /** + * Clips and translates the Graphics instance for painting on the double + * buffer. This has to be done, so that it reflects the component clip of the + * target component. + * + * @param root the root component (top-level container usually) + * @param target the component to be painted + * @param g the Graphics instance + */ + private void clipAndTranslateGraphics(Component root, Component target, + Graphics g) + { + Component parent = target.getParent(); + if (parent != root) + clipAndTranslateGraphics(root, parent, g); + + g.translate(target.getX(), target.getY()); + g.clipRect(0, 0, target.getWidth(), target.getHeight()); + } + + /** * Performs normal painting without double buffering. * * @param r the area that should be repainted |