public void paint(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   Component c;
   Point p;
   paintComponent(g);
   for (int i = 0; i < getComponentCount(); i++) {
     AffineTransform save = g.getTransform();
     c = getComponent(i);
     p = c.getLocation();
     g.translate((int) p.getX(), (int) p.getY());
     c.paint(g);
     g.setTransform(save);
   }
 }
 BufferedImage createImageFromComponent(Component comp) {
   BufferedImage retImage = null;
   if (comp == null) return retImage;
   try {
     GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gd = genv.getDefaultScreenDevice();
     GraphicsConfiguration gc = gd.getDefaultConfiguration();
     java.awt.image.ColorModel cm = gc.getColorModel();
     boolean hasAlpha = cm.hasAlpha();
     int cw = comp.getSize().width;
     int ch = comp.getSize().height;
     if (hasAlpha) {
       retImage = gc.createCompatibleImage(cw, ch);
     } else {
       retImage = new BufferedImage(cw, ch, BufferedImage.TYPE_INT_ARGB);
     }
     if (retImage == null) return retImage;
     Graphics og = retImage.getGraphics();
     comp.paint(og);
     og.dispose();
   } catch (Throwable t) {
   }
   return retImage;
 }