public void update(Graphics g) {
    Dimension size = getSize();
    if (offscreen == null)
      offscreen =
          createImage((size.width < 1) ? 1 : size.width, (size.height < 1) ? 1 : size.height);

    Graphics og = offscreen.getGraphics();
    if (og != null)
      try {
        og.setClip(g.getClip());

        og.setColor(getBackground());
        og.fillRect(0, 0, size.width, size.height);

        super.paint(og);
      } finally {
        og.dispose();
      }

    paint(g);
  }