title: JUNG: Paint graph on existing JPanel
body: <p>I am starting with JUNG and I get to draw a graph in the Jpanel of a newly created JFrame, but I am unable to paint the same Graph in an existing Panel of the program I am developing.</p>
  
  <p>The function I use is this:</p>
  
  <pre><code>private void demoGraph() {
          // Graph&lt;V, E&gt; where V is the type of the vertices and E is the type of the edges
          // Note showing the use of a SparseGraph rather than a SparseMultigraph
          Graph&lt;Integer, String&gt; g = new SparseGraph&lt;&gt;();
          // Add some vertices. From above we defined these to be type Integer.
          g.addVertex((Integer) 1);
          g.addVertex((Integer) 2);
          g.addVertex((Integer) 3);
          // g.addVertex((Integer)1);  // note if you add the same object again nothing changes
          // Add some edges. From above we defined these to be of type String
          // Note that the default is for undirected edges.
          g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
          g.addEdge("Edge-B", 2, 3);
  
          // Layout&lt;V, E&gt;, VisualizationComponent&lt;V,E&gt;
          Layout&lt;Integer, String&gt; layout = new CircleLayout(g);
          layout.setSize(new Dimension(300, 300));
          VisualizationViewer&lt;Integer, String&gt; vv = new VisualizationViewer&lt;&gt;(layout);
          vv.setPreferredSize(new Dimension(350, 350));
          // Setup up a new vertex to paint transformer...
          Transformer&lt;Integer, Paint&gt; vertexPaint = new Transformer&lt;Integer, Paint&gt;() {
              @Override
              public Paint transform(Integer i) {
                  return Color.GREEN;
              }
          };
          // Set up a new stroke Transformer for the edges
          float dash[] = {10.0f};
          final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
                  BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
          Transformer&lt;String, Stroke&gt; edgeStrokeTransformer = new Transformer&lt;String, Stroke&gt;() {
              @Override
              public Stroke transform(String s) {
                  return edgeStroke;
              }
          };
          vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
          vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
          vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
          vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
          vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
  
  
          // paint on a JPanel: NOT WORKING
          GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
          panel.setSize(this.graphPanel.getWidth(), this.graphPanel.getHeight());
          BorderLayout panelMapLayout = new BorderLayout();
          panel.setLayout(panelMapLayout);
          panel.setVisible(true);
          this.graphPanel.add(panel);
          this.graphPanel.revalidate();
          this.graphPanel.repaint();
  
          // Paint on a new JFrame: perfectly working
          JFrame frame = new JFrame("Simple Graph View 2");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(vv);
          frame.pack();
          frame.setVisible(true);
      }
  </code></pre>
  
  <p>Some guidance here is much appreciated.</p>