title: Is it possible to paint a JComponent and all its children to another component?
body: <p>I have an extended <code>JPanel</code> class called <code>GridPanel</code>. It lets you drag and drop images into it from a <code>JList</code>. The <code>GridPanel</code> lets you drag the images around with the mouse and rearrange them as you want. What I'm interested in is making a thumbnail view of the <code>GridPanel</code> component. </p>
  
  <p>If I understand correctly, setting a <code>JScrollPane</code>'s view to be <code>GridPanel</code> makes <code>GridPanel</code> a child of a <code>JViewPort</code>, which becomes a child of the <code>JScrollPane</code>. Currently <code>GridPanel</code> is already set to be the view of a <code>JScrollPane</code> and I'm pretty sure <code>GridPanel</code> can't have two parents. So I can't have two components share the same view, but I really only need the thumbnail view to paint a scaled visual copy of <code>GridPanel</code>.</p>
  
  <p>This leads to my question. Is it possible to copy what <code>GridPanel</code> paints, but paint it on a completely separate component? </p>
  
  <p>This is an example of what I've tried, in case I'm not being understood.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  
  public class TestMain {
  public static void main(String[] a) {
      Color[] colors = new Color[]{Color.green, Color.red, Color.blue, Color.yellow};
  
  
      final JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationByPlatform(true);
      JPanel content = new JPanel();
      frame.setContentPane(content);
      content.setLayout(new FlowLayout());
      //using variable names to try and help relate to my question
      final JPanel gridPanel = new JPanel();
      gridPanel.setPreferredSize(new Dimension(200,200));
      gridPanel.setLayout(new GridLayout(2, 2));
      JLabel label;
      for (Color c: colors){
          label = new JLabel();
          label.setOpaque(true);
          label.setBackground(c);
          gridPanel.add(label);
      }
  
      JScrollPane gridScroll = new JScrollPane(gridPanel);
  
      final JScrollPane thumbnailScroll = new JScrollPane();
      thumbnailScroll.setPreferredSize(new Dimension(200,200));
  
      JButton tryThumbnailView = new JButton("Activate Thumbnail");
      tryThumbnailView.addActionListener(new ActionListener(){
          @Override
          public void actionPerformed(ActionEvent arg0) {
              thumbnailScroll.setViewportView(gridPanel);
              frame.repaint();
  
          }
      });
      content.add(tryThumbnailView);
  
      content.add(gridScroll);
      content.add(thumbnailScroll);
  
      frame.pack();
      frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>What I would like to have happen is for both components to show the same set of colored <code>JLabels</code>, without duplicating those <code>JLabels</code>.</p>