title: Formatting a JGraph graph using com.jgraph.layout - refreshing the display
body: <p>I'm writing my very first program in Java that actually does UI, so please bear with me if the answer to this is obvious.</p>
  
  <p>I'm using JGraph 5 (5.14) to visualize a graph created by JGrapht (0.8.3).</p>
  
  <p>I can create the graph with JGrapht just fine, and I believe it gets converted to JGraph OK using org.jgrapht.ext.JGraphModelAdapter.  The problem is, when the result is displayed in a window (I'm using a panel in a JApplet) all the vertices are displayed on top of another.</p>
  
  <p>Someone else had this problem (<a href="https://stackoverflow.com/questions/8496114/jgraph-layout-does-not-work">JGraph Layout Does Not Work</a>) and I tried the solution presented there, but then only two nodes are displayed.  Basically, I just want the graph displayed in some way where the nodes are separate from each other.</p>
  
  <p>Some code is worth a thousand words, so here is what I currently have, which only displays two nodes (there are 219 in the graph):</p>
  
  <pre><code>class ourGraphVisualizer extends JApplet
  {
  
  private static final Color DEFAULT_BG_COLOR = Color.decode("#FAFBFF");
  private static final Dimension DEFAULT_SIZE = new Dimension(1280, 1024);
  
  // this init overrides the JApplet.init().  Our class here extends JApplet so we can do the visualization
  public void init(ListenableDirectedWeightedGraph&lt;String, DefaultWeightedEdge&gt; theGraph)
  {
      JGraphModelAdapter&lt;String, DefaultWeightedEdge&gt; jgAdapter;
  
      JPanel panel = new JPanel();
      panel.setPreferredSize(DEFAULT_SIZE);
  
      JScrollPane scrollpane = new JScrollPane(panel);
      scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  
      this.getContentPane().add(scrollpane, BorderLayout.CENTER);
  
      JFrame frame = new JFrame();
  
      frame.add(this);
      frame.setTitle("Call Graph, " + theGraph.vertexSet().size() + "nodes");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setPreferredSize(DEFAULT_SIZE);
  
      jgAdapter = new JGraphModelAdapter&lt;String, DefaultWeightedEdge&gt;(theGraph);
  
      JGraph jgraph = new JGraph(jgAdapter);
  
      panel.add(jgraph);
      resize(DEFAULT_SIZE);
  
      // Let's see if we can lay it out
      JGraphFacade jgf = new JGraphFacade(jgraph);
      JGraphFastOrganicLayout layoutifier = new JGraphFastOrganicLayout();
      layoutifier.run(jgf);
      System.out.println("Layout complete");
  
      final Map nestedMap = jgf.createNestedMap(true, true);
      jgraph.getGraphLayoutCache().edit(nestedMap);
  
      jgraph.getGraphLayoutCache().update();
      jgraph.refresh();
  
      frame.setVisible(true);
      panel.setVisible(true);
      scrollpane.setVisible(true);
  }
  </code></pre>
  
  <p>Any constructive suggestions/help/inspiration will be greatly appreciated!</p>
  
  <p>Thanks...</p>
  
  <p>-Eric</p>