Question

I have the following code:

package jung;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.algorithms.layout.*;
import java.awt.Dimension;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import javax.swing.JFrame;
/**
 *
 * @author studnet
 */
public class Jung {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Graph<Integer, String> g = new DirectedSparseGraph<Integer, String>();
    g.addVertex((Integer)1);
    g.addVertex((Integer)2);
    g.addVertex((Integer)3); 

    g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
    g.addEdge("Edge-B", 2, 3);  

    FRLayout2<Integer, String> layout = new FRLayout2(g, new Dimension(600, 600));
    while ( !layout.done() )
        layout.step();
    //Layout<Integer, String> layout = new CircleLayout(g);
    //Layout<Integer, String> layout = new FRLayout(g);
    VisualizationViewer<Integer,String> vv = new VisualizationViewer<Integer,String>(layout);
    //vv.setPreferredSize(new Dimension(600,600)); //Sets the viewing area size

    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);


    // TODO code application logic here
    }
}

But all the vertices are in the upper left corner, any suggestions?

Was it helpful?

Solution 2

FRLayout2 doestn' work I swtichd to FRLayout.

OTHER TIPS

I believe you might have to call

layout.initialize()

which will run the preparation code.

EDIT:

I was wrong about the above. After glimpsing over a diff of FRLayout and FRLayout2 I think there might be some logical error somewhere around:

fvd1.setLocation(0, 0);
...
fvd1.setLocation(fvd1.getX()+2 * xDelta * forceOverDeltaLength,                 
                 fvd1.getY()+ 2 * yDelta * forceOverDeltaLength);

It also looks like FRLayout2 isn't too strict with regards to the original algorithm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top