我有以下代码:
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
}
}
但是所有的顶点都在左上角,有什么建议吗?