开发者

how can i draw a tree hierarchy using JUNG?

开发者 https://www.devze.com 2022-12-25 22:32 出处:网络
I\'m new to JUNG. I tried to draw a graph of a tree using the TreeLayout but the tree never comes out like a real tree. Every time the开发者_开发百科 tree looks different. How can I make the tree look

I'm new to JUNG. I tried to draw a graph of a tree using the TreeLayout but the tree never comes out like a real tree. Every time the开发者_开发百科 tree looks different. How can I make the tree look like a normal tree with the root on top & the rest of the nodes descending from it?


You have to Initialize the TreeLayout after adding the Vertexes to the graph, I tried that and it worked for me.

You have to do something like the following: (please note that this is a 1 year old code that i had, you might find it to be a little out dated)

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 Is the class which represents a vertex in the graph, GraphEdge represents the edges in your graph.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号