我是JUNG的新手。我尝试使用TreeLayout绘制一棵树形图,但是树形图从未像真正的树那样呈现出来。每次树都看起来不同。如何使树看起来像一个正常的树,根在顶部,其余节点从上往下排列?
在向图形添加顶点后,您必须初始化TreeLayout
。我尝试过这样做,对我有用。
您需要执行以下操作:(请注意,这是一年前的代码,可能有些过时)
Layout<GraphVertex, GraphEdge> layout; //create a layout
layout = new TreeLayout<GraphVertex, GraphEdge>((Forest<GraphVertex, GraphEdge>) g);
// initialize your layout using the graph you created, which has to be of type forest
vv.setGraphLayout(layout);
// set the layout of the visualization viewer you are using to be the layout you just created (the tree layout)
GraphVertex
是代表图中顶点的类,GraphEdge
代表图中的边。