ArrayList repaintOrder = new ArrayList(dirtyComponents.size()); repaintOrder.addAll(dirtyComponents.keySet());
repaintOrder.addAll(dirtyComponentsWork.keySet());
  public void paintDirtyRegions()      {    // Short cicuit if there is nothing to paint.    if (dirtyComponents.size() == 0)      return;    synchronized (dirtyComponents)      {        // We sort the components by their size here. This way we have a good        // chance that painting the bigger components also paints the smaller        // components and we don't need to paint them twice.        ArrayList repaintOrder = new ArrayList(dirtyComponents.size());        repaintOrder.addAll(dirtyComponents.keySet());        if (comparator == null)          comparator = new ComponentComparator();        Collections.sort(repaintOrder, comparator);        repaintUnderway = true;        for (Iterator i = repaintOrder.iterator(); i.hasNext();)      {        JComponent comp = (JComponent) i.next();        // If a component is marked completely clean in the meantime, then skip        // it.            Rectangle damaged = (Rectangle) dirtyComponents.get(comp);        if (damaged == null || damaged.isEmpty())          continue;        comp.paintImmediately(damaged);            dirtyComponents.remove(comp);          }        repaintUnderway = false;        commitRemainingBuffers();      }  }