Rectangle damaged = getDirtyRegion(comp); if (damaged.width == 0 || damaged.height == 0) continue; JRootPane root = comp.getRootPane();  if (root == null) continue; Rectangle rootDamage = SwingUtilities.convertRectangle(comp, damaged, root); if (! roots.containsKey(root)) { roots.put(root, rootDamage); } else { roots.put(root, ((Rectangle)roots.get(root)).union(rootDamage)); }
comp.paintImmediately(damaged);
  public void paintDirtyRegions()  {    // step 1: pull out roots and calculate spanning damage    HashMap roots = new HashMap();    for (Enumeration e = dirtyComponents.keys(); e.hasMoreElements(); )      {        JComponent comp = (JComponent) e.nextElement();        if (! (comp.isVisible() && comp.isShowing()))          continue;        Rectangle damaged = getDirtyRegion(comp);        if (damaged.width == 0 || damaged.height == 0)          continue;        JRootPane root = comp.getRootPane();        // If the component has no root, no repainting will occur.        if (root == null)          continue;        Rectangle rootDamage = SwingUtilities.convertRectangle(comp, damaged, root);        if (! roots.containsKey(root))          {            roots.put(root, rootDamage);          }        else          {            roots.put(root, ((Rectangle)roots.get(root)).union(rootDamage));          }      }    dirtyComponents.clear();    // step 2: paint those roots    Iterator i = roots.entrySet().iterator();    while(i.hasNext())      {        Map.Entry ent = (Map.Entry) i.next();        JRootPane root = (JRootPane) ent.getKey();        Rectangle rect = (Rectangle) ent.getValue();        root.paintImmediately(rect);                	      }  }