title: How to draw nodes and edges on a custom java swing component that extends JPanel with GraphStream (or another library)?
body: <p>I'm creating a user interface for a java swing program that should be able to allow the user to create a network of nodes, connected by edges. The user is allowed to label those nodes and edges.</p>
  
  <p>The UI currently has a custom graphical component that extends <code>JPanel</code> and it is meaningful on it's own, having working operations such as zoom and drag. I'm trying to use the GraphStream library (<a href="http://graphstream-project.org/" rel="nofollow">http://graphstream-project.org/</a>) to turn this custom panel into a <code>View</code> that supports GraphStream <code>Graph</code>s. Since GraphStream comes with a <code>DefaultView</code> class that is able to show basic graphs out of the box and extends <code>JPanel</code>, I decided to modify my map component so that it extends <code>DefaultView</code>. So my class definition for the background component is now</p>
  
  <pre><code>public class CustomPanel extends DefaultView implements ICustomListener
  {
      public CustomPanel(Viewer viewer, String identifier, GraphRenderer renderer)
      {
          super(viewer, identifier, renderer);
          ...
      }
  }
  </code></pre>
  
  <p>However, the component fails to display any graphs or drawing capabilities. This is how I proceeded to form a test graph</p>
  
  <pre><code>Graph graph = new GraphicGraph("embedded");
  Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
  
  Node a = graph.addNode("A");
  a.addAttribute("xy", 0, 0);
  Node b = graph.addNode("B");
  b.addAttribute("xy", 10, 0);
  Node c = graph.addNode("C");
  c.addAttribute("xy", 10, 10);
  graph.addEdge("AB","A","B");
  
  //This is where I assume the GraphStream magic should happen.
  CustomPanel myPanel = new CustomPanel(viewer, "defaultView", Viewer.newGraphRenderer());
  viewer.addView(myPanel);
  myPanel.display((GraphicGraph)(graph), true);
  </code></pre>
  
  <p>I am able to display the same graph with </p>
  
  <pre><code>viewer.addDefaultView(true);
  </code></pre>
  
  <p>but it opens in a new window.</p>
  
  <p>So what am I doing wrong or is it even possible to display graphs with GraphStream on custom components? If there is another library that could do this I would be thankful to know. I am aware of JUNG2 and Java2D but have not  tried them yet. I could also live with a solution that opens an editor in another window, but I would still need my CustomPanel as the background.</p>