如何使用JUNG绘制树形层次结构?

Dar*_*eis 7 java tree layout graph jung

我是JUNG的新手.我尝试使用TreeLayout绘制树的图形,但树永远不会像真正的树一样出现.每次树看起来都不一样.如何使树看起来像普通树,其根部位于顶部,其余节点从其下降?

Dar*_*eis 5

你必须TreeLayout在将Vertexes添加到图表后初始化,我尝试了它,它对我有用.

您必须执行以下操作:(请注意,这是一个1年前的代码,您可能会发现它有点过时了)

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)
Run Code Online (Sandbox Code Playgroud)

GraphVertex表示图中顶点的类是否表示图中GraphEdge的边.